{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAsEM,SAAS,0CACd,KAAyB,EACzB,KAAmB,EACnB,GAAkC;IAElC,IAAI,mBAAC,kBAAkB,iBAAM,SAAS,WAAE,OAAO,EAAE,GAAG,YAAW,GAAG;IAElE,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,kBAAkB,IAAI,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAChF,QAAQ,IAAI,CAAC;IAGf,IAAI,WAAW,CAAA,GAAA,yCAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IACrD,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,yCAAgB,EAAE;QAClC,GAAG,UAAU;aACb;QACA,kBAAkB,MAAM,gBAAgB;QACxC,YAAY,MAAM,UAAU;QAC5B,cAAc,MAAM,YAAY;yBAChC;QACA,cAAc;IAChB;IAEA,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC,OAAO;QAClB,SAAS,MAAM,OAAO;QACtB,UAAU,MAAM,QAAQ;QACxB,uBAAuB,MAAM,qBAAqB;IACpD;IAEA,OAAO;QACL,WAAW,CAAA,GAAA,yCAAS,EAClB,UACA;uBAAC;qBAAW;QAAO,GACnB;YACE,MAAM;YACN,GAAG,SAAS;YACZ,WAAW,CAAA;gBACT,gGAAgG;gBAChG,IAAI,EAAE,GAAG,KAAK,YAAY,MAAM,qBAAqB,EACnD,UAAU,SAAS,GAAG;YAE1B;QACF;IAEJ;AACF","sources":["packages/react-aria/src/menu/useMenu.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n  AriaLabelingProps,\n  CollectionBase,\n  DOMAttributes,\n  DOMProps,\n  FocusStrategy,\n  Key,\n  KeyboardDelegate,\n  KeyboardEvents,\n  MultipleSelection,\n  RefObject\n} from '@react-types/shared';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {menuData} from './utils';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TreeState} from 'react-stately/useTreeState';\nimport {useSelectableList} from '../selection/useSelectableList';\n\nexport interface MenuProps<T> extends CollectionBase<T>, MultipleSelection {\n  /** Where the focus should be set. */\n  autoFocus?: boolean | FocusStrategy;\n  /** Whether keyboard navigation is circular. */\n  shouldFocusWrap?: boolean;\n  /** Handler that is called when an item is selected. */\n  onAction?: (key: Key) => void;\n  /** Handler that is called when the menu should close after selecting an item. */\n  onClose?: () => void;\n}\n\nexport interface AriaMenuProps<T> extends MenuProps<T>, DOMProps, AriaLabelingProps {\n  /**\n   * Whether pressing the escape key should clear selection in the menu or not.\n   *\n   * Most experiences should not modify this option as it eliminates a keyboard user's ability to\n   * easily clear selection. Only use if the escape key is being handled externally or should not\n   * trigger selection clearing contextually.\n   *\n   * @default 'clearSelection'\n   */\n  escapeKeyBehavior?: 'clearSelection' | 'none';\n}\n\nexport interface MenuAria {\n  /** Props for the menu element. */\n  menuProps: DOMAttributes;\n}\n\nexport interface AriaMenuOptions<T> extends Omit<AriaMenuProps<T>, 'children'>, KeyboardEvents {\n  /** Whether the menu uses virtual scrolling. */\n  isVirtualized?: boolean;\n  /**\n   * An optional keyboard delegate implementation for type to select,\n   * to override the default.\n   */\n  keyboardDelegate?: KeyboardDelegate;\n  /**\n   * Whether the menu items should use virtual focus instead of being focused directly.\n   */\n  shouldUseVirtualFocus?: boolean;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a menu component.\n * A menu displays a list of actions or options that a user can choose.\n *\n * @param props - Props for the menu.\n * @param state - State for the menu, as returned by `useListState`.\n */\nexport function useMenu<T>(\n  props: AriaMenuOptions<T>,\n  state: TreeState<T>,\n  ref: RefObject<HTMLElement | null>\n): MenuAria {\n  let {shouldFocusWrap = true, onKeyDown, onKeyUp, ...otherProps} = props;\n\n  if (!props['aria-label'] && !props['aria-labelledby'] && process.env.NODE_ENV !== 'production') {\n    console.warn('An aria-label or aria-labelledby prop is required for accessibility.');\n  }\n\n  let domProps = filterDOMProps(props, {labelable: true});\n  let {listProps} = useSelectableList({\n    ...otherProps,\n    ref,\n    selectionManager: state.selectionManager,\n    collection: state.collection,\n    disabledKeys: state.disabledKeys,\n    shouldFocusWrap,\n    linkBehavior: 'override'\n  });\n\n  menuData.set(state, {\n    onClose: props.onClose,\n    onAction: props.onAction,\n    shouldUseVirtualFocus: props.shouldUseVirtualFocus\n  });\n\n  return {\n    menuProps: mergeProps(\n      domProps,\n      {onKeyDown, onKeyUp},\n      {\n        role: 'menu',\n        ...listProps,\n        onKeyDown: e => {\n          // don't clear the menu selected keys if the user is presses escape since escape closes the menu\n          if (e.key !== 'Escape' || props.shouldUseVirtualFocus) {\n            listProps.onKeyDown?.(e);\n          }\n        }\n      }\n    )\n  };\n}\n"],"names":[],"version":3,"file":"useMenu.mjs.map"}