{"version":3,"file":"ToggleMenuItem.cjs","names":[],"sources":["../../../src/components/Menu/ToggleMenuItem.tsx"],"sourcesContent":["/*\nCopyright 2023, 2024 New Vector Ltd.\n\nSPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial\nPlease see LICENSE files in the repository root for full details.\n*/\n\nimport React, {\n  type ComponentProps,\n  forwardRef,\n  useCallback,\n  useId,\n} from \"react\";\nimport { MenuItem } from \"./MenuItem\";\nimport { ToggleInput } from \"../Form/Controls/Toggle\";\n\ntype Props = Pick<\n  ComponentProps<typeof MenuItem>,\n  \"className\" | \"Icon\" | \"label\" | \"onSelect\" | \"disabled\" | \"onClick\"\n> & {\n  /**\n   * Whether the toggle is checked.\n   */\n  checked: boolean;\n};\n\n/**\n * A menu item with a toggle control.\n * Must be used within a compound Menu or other `menu` or `menubar` aria role subtree.\n */\nexport const ToggleMenuItem = forwardRef<HTMLInputElement, Props>(\n  function ToggleMenuItem(\n    { className, Icon, label, onSelect, checked, disabled, onClick },\n    ref,\n  ) {\n    const toggleId = useId();\n    // The toggle is controlled and we intend to ignore its events. We do need\n    // to at least set onChange though to make React happy.\n    const onChange = useCallback(() => {}, []);\n\n    // <label> elements are not allowed to have a role like menuitemcheckbox, so\n    // we must instead use a plain <div> for the menu item and use aria-checked\n    // etc. to communicate its state.\n    return (\n      <MenuItem\n        as=\"button\"\n        role=\"menuitemcheckbox\"\n        aria-checked={checked}\n        className={className}\n        Icon={Icon}\n        label={label}\n        hideChevron\n        onSelect={onSelect}\n        disabled={disabled}\n        onClick={onClick}\n      >\n        <ToggleInput\n          id={toggleId}\n          ref={ref}\n          // This is purely cosmetic; really the whole MenuItem is the toggle.\n          aria-hidden\n          tabIndex={-1}\n          checked={checked}\n          disabled={disabled}\n          onChange={onChange}\n        />\n      </MenuItem>\n    );\n  },\n);\n"],"mappings":";;;;;;;;;;;AA8BA,IAAa,kBAAA,GAAA,MAAA,YACX,SAAS,eACP,EAAE,WAAW,MAAM,OAAO,UAAU,SAAS,UAAU,WACvD,KACA;CACA,MAAM,YAAA,GAAA,MAAA,QAAkB;CAGxB,MAAM,YAAA,GAAA,MAAA,mBAA6B,IAAI,EAAE,CAAC;AAK1C,QACE,iBAAA,GAAA,kBAAA,KAAC,iBAAA,UAAD;EACE,IAAG;EACH,MAAK;EACL,gBAAc;EACH;EACL;EACC;EACP,aAAA;EACU;EACA;EACD;YAET,iBAAA,GAAA,kBAAA,KAAC,eAAA,aAAD;GACE,IAAI;GACC;GAEL,eAAA;GACA,UAAU;GACD;GACC;GACA;GACV,CAAA;EACO,CAAA;EAGhB"}