{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport { useTextField } from \"@react-aria/textfield\";\nimport { useMessageFormatter } from \"@react-aria/i18n\";\nimport { useMenuTrigger } from \"@react-aria/menu\";\nimport { ListKeyboardDelegate, useSelectableCollection } from \"@react-aria/selection\";\nimport { getItemId, listIds } from \"@react-aria/listbox\";\nimport { getItemCount } from \"@react-stately/collections\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport { chain, isAppleDevice, mergeProps, useLabels } from \"@react-aria/utils\";\nimport { ariaHideOutside } from \"@react-aria/overlays\";\nimport { announce } from \"@react-aria/live-announcer\";\nimport _babelRuntimeHelpersEsmInteropRequireDefault from \"@babel/runtime/helpers/esm/interopRequireDefault\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nvar $f1639f2754c31f58763b8cb015a6ecd6$exports = {};\n$f1639f2754c31f58763b8cb015a6ecd6$exports = JSON.parse(\"{\\\"focusAnnouncement\\\":\\\"{isGroupChange, select, true {Entered group {groupTitle}, with {groupCount, plural, one {# option} other {# options}}. } other {}}{optionText}{isSelected, select, true {, selected} other {}}\\\",\\\"countAnnouncement\\\":\\\"{optionCount, plural, one {# option} other {# options}} available.\\\",\\\"selectedAnnouncement\\\":\\\"{optionText}, selected\\\",\\\"buttonLabel\\\":\\\"Show suggestions\\\",\\\"listboxLabel\\\":\\\"Suggestions\\\"}\");\nvar $be26f9e765ed670e72d5b46ae9eff69a$var$intlMessages = {\n  \"en-US\": _babelRuntimeHelpersEsmInteropRequireDefault($f1639f2754c31f58763b8cb015a6ecd6$exports).default\n};\nexport function useComboBox(props, state) {\n  var _focusedItem$parentKe, _state$selectionManag;\n\n  var buttonRef = props.buttonRef,\n      popoverRef = props.popoverRef,\n      inputRef = props.inputRef,\n      listBoxRef = props.listBoxRef,\n      keyboardDelegate = props.keyboardDelegate,\n      isReadOnly = props.isReadOnly,\n      isDisabled = props.isDisabled;\n  var formatMessage = useMessageFormatter($be26f9e765ed670e72d5b46ae9eff69a$var$intlMessages);\n\n  var _useMenuTrigger = useMenuTrigger({\n    type: 'listbox'\n  }, state, buttonRef),\n      menuTriggerProps = _useMenuTrigger.menuTriggerProps,\n      menuProps = _useMenuTrigger.menuProps;\n\n  listIds.set(state, menuProps.id);\n  var delegate = useMemo(function () {\n    return keyboardDelegate || new ListKeyboardDelegate(state.collection, state.disabledKeys, listBoxRef);\n  }, [keyboardDelegate, state.collection, state.disabledKeys, listBoxRef]);\n\n  var _useSelectableCollect = useSelectableCollection({\n    selectionManager: state.selectionManager,\n    keyboardDelegate: delegate,\n    disallowTypeAhead: true,\n    disallowEmptySelection: true,\n    ref: inputRef\n  }),\n      collectionProps = _useSelectableCollect.collectionProps;\n\n  var onKeyDown = function onKeyDown(e) {\n    switch (e.key) {\n      case 'Enter':\n      case 'Tab':\n        state.commit();\n        break;\n\n      case 'Escape':\n        state.close();\n        break;\n\n      case 'ArrowDown':\n        state.open('first');\n        break;\n\n      case 'ArrowUp':\n        state.open('last');\n        break;\n\n      case 'ArrowLeft':\n      case 'ArrowRight':\n        state.selectionManager.setFocusedKey(null);\n        break;\n    }\n  };\n\n  var onBlur = function onBlur(e) {\n    var _popoverRef$current;\n\n    if (e.relatedTarget === buttonRef.current || ((_popoverRef$current = popoverRef.current) == null ? void 0 : _popoverRef$current.contains(e.relatedTarget))) {\n      return;\n    }\n\n    if (props.onBlur) {\n      props.onBlur(e);\n    }\n\n    state.setFocused(false);\n  };\n\n  var onFocus = function onFocus(e) {\n    if (state.isFocused) {\n      return;\n    }\n\n    if (props.onFocus) {\n      props.onFocus(e);\n    }\n\n    state.setFocused(true);\n  };\n\n  var _useTextField = useTextField(_babelRuntimeHelpersEsmExtends({}, props, {\n    onChange: state.setInputValue,\n    onKeyDown: !isReadOnly && chain(state.isOpen && collectionProps.onKeyDownCapture, onKeyDown),\n    onBlur: onBlur,\n    value: state.inputValue,\n    onFocus: onFocus,\n    autoComplete: 'off'\n  }), inputRef),\n      labelProps = _useTextField.labelProps,\n      inputProps = _useTextField.inputProps;\n\n  var onPress = function onPress(e) {\n    if (e.pointerType === 'touch') {\n      inputRef.current.focus();\n      state.toggle();\n    }\n  };\n\n  var onPressStart = function onPressStart(e) {\n    if (e.pointerType !== 'touch') {\n      inputRef.current.focus();\n      state.toggle(e.pointerType === 'keyboard' || e.pointerType === 'virtual' ? 'first' : null);\n    }\n  };\n\n  var triggerLabelProps = useLabels({\n    id: menuTriggerProps.id,\n    'aria-label': formatMessage('buttonLabel'),\n    'aria-labelledby': props['aria-labelledby'] || labelProps.id\n  });\n  var listBoxProps = useLabels({\n    id: menuProps.id,\n    'aria-label': formatMessage('listboxLabel'),\n    'aria-labelledby': props['aria-labelledby'] || labelProps.id\n  });\n  var lastEventTime = useRef(0);\n\n  var onTouchEnd = function onTouchEnd(e) {\n    if (isDisabled || isReadOnly) {\n      return;\n    }\n\n    if (e.timeStamp - lastEventTime.current < 500) {\n      e.preventDefault();\n      inputRef.current.focus();\n      return;\n    }\n\n    var rect = e.target.getBoundingClientRect();\n    var touch = e.changedTouches[0];\n    var centerX = Math.ceil(rect.left + .5 * rect.width);\n    var centerY = Math.ceil(rect.top + .5 * rect.height);\n\n    if (touch.clientX === centerX && touch.clientY === centerY) {\n      e.preventDefault();\n      inputRef.current.focus();\n      state.toggle();\n      lastEventTime.current = e.timeStamp;\n    }\n  };\n\n  var focusedItem = state.selectionManager.focusedKey != null && state.isOpen ? state.collection.getItem(state.selectionManager.focusedKey) : undefined;\n  var sectionKey = (_focusedItem$parentKe = focusedItem == null ? void 0 : focusedItem.parentKey) != null ? _focusedItem$parentKe : null;\n  var itemKey = (_state$selectionManag = state.selectionManager.focusedKey) != null ? _state$selectionManag : null;\n  var lastSection = useRef(sectionKey);\n  var lastItem = useRef(itemKey);\n  useEffect(function () {\n    if (isAppleDevice() && focusedItem != null && itemKey !== lastItem.current) {\n      var isSelected = state.selectionManager.isSelected(itemKey);\n      var section = sectionKey != null ? state.collection.getItem(sectionKey) : null;\n      var sectionTitle = (section == null ? void 0 : section['aria-label']) || (typeof (section == null ? void 0 : section.rendered) === 'string' ? section.rendered : '') || '';\n      var announcement = formatMessage('focusAnnouncement', {\n        isGroupChange: section && sectionKey !== lastSection.current,\n        groupTitle: sectionTitle,\n        groupCount: section ? _toConsumableArray(section.childNodes).length : 0,\n        optionText: focusedItem['aria-label'] || focusedItem.textValue || '',\n        isSelected: isSelected\n      });\n      announce(announcement);\n    }\n\n    lastSection.current = sectionKey;\n    lastItem.current = itemKey;\n  });\n  var optionCount = getItemCount(state.collection);\n  var lastSize = useRef(optionCount);\n  var lastOpen = useRef(state.isOpen);\n  useEffect(function () {\n    var didOpenWithoutFocusedItem = state.isOpen !== lastOpen.current && (state.selectionManager.focusedKey == null || isAppleDevice());\n\n    if (state.isOpen && (didOpenWithoutFocusedItem || optionCount !== lastSize.current)) {\n      var announcement = formatMessage('countAnnouncement', {\n        optionCount: optionCount\n      });\n      announce(announcement);\n    }\n\n    lastSize.current = optionCount;\n    lastOpen.current = state.isOpen;\n  });\n  var lastSelectedKey = useRef(state.selectedKey);\n  useEffect(function () {\n    if (isAppleDevice() && state.isFocused && state.selectedItem && state.selectedKey !== lastSelectedKey.current) {\n      var optionText = state.selectedItem['aria-label'] || state.selectedItem.textValue || '';\n      var announcement = formatMessage('selectedAnnouncement', {\n        optionText: optionText\n      });\n      announce(announcement);\n    }\n\n    lastSelectedKey.current = state.selectedKey;\n  });\n  useEffect(function () {\n    if (state.isOpen) {\n      return ariaHideOutside([inputRef.current, popoverRef.current]);\n    }\n  }, [state.isOpen, inputRef, popoverRef]);\n  return {\n    labelProps: labelProps,\n    buttonProps: _babelRuntimeHelpersEsmExtends({}, menuTriggerProps, triggerLabelProps, {\n      excludeFromTabOrder: true,\n      onPress: onPress,\n      onPressStart: onPressStart\n    }),\n    inputProps: mergeProps(inputProps, {\n      role: 'combobox',\n      'aria-expanded': menuTriggerProps['aria-expanded'],\n      'aria-controls': state.isOpen ? menuProps.id : undefined,\n      'aria-autocomplete': 'list',\n      'aria-activedescendant': focusedItem ? getItemId(state, focusedItem.key) : undefined,\n      onTouchEnd: onTouchEnd,\n      autoCorrect: 'off',\n      spellCheck: 'false'\n    }),\n    listBoxProps: mergeProps(menuProps, listBoxProps)\n  };\n}","map":{"version":3,"sources":["packages/@react-aria/combobox/intl/en-US.json","packages/@react-aria/combobox/src/useComboBox.ts"],"names":["JSON","isDisabled","formatMessage","useMessageFormatter","menuProps","useMenuTrigger","type","listIds","delegate","useMemo","keyboardDelegate","state","collectionProps","useSelectableCollection","selectionManager","disallowTypeAhead","disallowEmptySelection","ref","inputRef","onKeyDown","e","onBlur","buttonRef","popoverRef","props","onFocus","inputProps","useTextField","onChange","chain","value","autoComplete","onPress","onPressStart","triggerLabelProps","useLabels","id","menuTriggerProps","labelProps","listBoxProps","lastEventTime","useRef","onTouchEnd","rect","touch","centerX","Math","centerY","focusedItem","sectionKey","itemKey","lastSection","lastItem","useEffect","isAppleDevice","isSelected","section","sectionTitle","announcement","isGroupChange","groupTitle","groupCount","optionText","announce","optionCount","getItemCount","lastSize","lastOpen","didOpenWithoutFocusedItem","lastSelectedKey","ariaHideOutside","buttonProps","excludeFromTabOrder","mergeProps","role","getItemId","autoCorrect","spellCheck"],"mappings":";;;;;;;;;;;;;;AAAA,yCAAA,GAAiBA,IAAI,CAAJA,KAAAA,CAAjB,mbAAiBA,CAAjB;;;;OC2DO,SAAA,WAAA,CAAA,KAAA,EAAA,KAAA,EAA4F;AAAA,MAAA,qBAAA,EAAA,qBAAA;;AAAA,MAC7F,SAD6F,GACjG,KADiG,CAC7F,SAD6F;AAAA,MAC7F,UAD6F,GACjG,KADiG,CAC7F,UAD6F;AAAA,MAC7F,QAD6F,GACjG,KADiG,CAC7F,QAD6F;AAAA,MAC7F,UAD6F,GACjG,KADiG,CAC7F,UAD6F;AAAA,MAC7F,gBAD6F,GACjG,KADiG,CAC7F,gBAD6F;AAAA,MAC7F,UAD6F,GACjG,KADiG,C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,GAAY,CAAZ,GANH,SAAA;AAOjCN,MAAAA,UAPiC,EAOjCA,UAPiC;AASjCkC,MAAAA,WAAW,EATsB,KAAA;AAWjCC,MAAAA,UAAU,EAAE;AAXqB,KAAb,CATjB;AAsBLtC,IAAAA,YAAY,EAAEkC,UAAU,CAAA,SAAA,EAAA,YAAA;AAtBnB,GAAP;AAwBD","sourcesContent":["{\n  \"focusAnnouncement\": \"{isGroupChange, select, true {Entered group {groupTitle}, with {groupCount, plural, one {# option} other {# options}}. } other {}}{optionText}{isSelected, select, true {, selected} other {}}\",\n  \"countAnnouncement\": \"{optionCount, plural, one {# option} other {# options}} available.\",\n  \"selectedAnnouncement\": \"{optionText}, selected\",\n  \"buttonLabel\": \"Show suggestions\",\n  \"listboxLabel\": \"Suggestions\"\n}\n","/*\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 {announce} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {ariaHideOutside} from '@react-aria/overlays';\nimport {chain, isAppleDevice, mergeProps, useLabels} from '@react-aria/utils';\nimport {ComboBoxProps} from '@react-types/combobox';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {FocusEvent, HTMLAttributes, InputHTMLAttributes, KeyboardEvent, RefObject, TouchEvent, useEffect, useMemo, useRef} from 'react';\nimport {getItemCount} from '@react-stately/collections';\nimport {getItemId, listIds} from '@react-aria/listbox';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {KeyboardDelegate, PressEvent} from '@react-types/shared';\nimport {ListKeyboardDelegate, useSelectableCollection} from '@react-aria/selection';\nimport {useMenuTrigger} from '@react-aria/menu';\nimport {useMessageFormatter} from '@react-aria/i18n';\nimport {useTextField} from '@react-aria/textfield';\n\ninterface AriaComboBoxProps<T> extends ComboBoxProps<T> {\n  /** The ref for the input element. */\n  inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement>,\n  /** The ref for the list box popover. */\n  popoverRef: RefObject<HTMLDivElement>,\n  /** The ref for the list box. */\n  listBoxRef: RefObject<HTMLElement>,\n  /** The ref for the list box popup trigger button.  */\n  buttonRef: RefObject<HTMLElement>,\n  /** An optional keyboard delegate implementation, to override the default. */\n  keyboardDelegate?: KeyboardDelegate\n}\n\ninterface ComboBoxAria {\n  /** Props for the combo box menu trigger button. */\n  buttonProps: AriaButtonProps,\n  /** Props for the combo box input element. */\n  inputProps: InputHTMLAttributes<HTMLInputElement>,\n  /** Props for the combo box menu. */\n  listBoxProps: HTMLAttributes<HTMLElement>,\n  /** Props for the combo box label element. */\n  labelProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a combo box component.\n * A combo box combines a text input with a listbox, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the combo box.\n * @param state - State for the select, as returned by `useComboBoxState`.\n */\nexport function useComboBox<T>(props: AriaComboBoxProps<T>, state: ComboBoxState<T>): ComboBoxAria {\n  let {\n    buttonRef,\n    popoverRef,\n    inputRef,\n    listBoxRef,\n    keyboardDelegate,\n    // completionMode = 'suggest',\n    isReadOnly,\n    isDisabled\n  } = props;\n\n  let formatMessage = useMessageFormatter(intlMessages);\n  let {menuTriggerProps, menuProps} = useMenuTrigger(\n    {\n      type: 'listbox'\n    },\n    state,\n    buttonRef\n  );\n\n  // Set listbox id so it can be used when calling getItemId later\n  listIds.set(state, menuProps.id);\n\n  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n  // When virtualized, the layout object will be passed in as a prop and override this.\n  let delegate = useMemo(() =>\n    keyboardDelegate ||\n    new ListKeyboardDelegate(state.collection, state.disabledKeys, listBoxRef)\n  , [keyboardDelegate, state.collection, state.disabledKeys, listBoxRef]);\n\n  // Use useSelectableCollection to get the keyboard handlers to apply to the textfield\n  let {collectionProps} = useSelectableCollection({\n    selectionManager: state.selectionManager,\n    keyboardDelegate: delegate,\n    disallowTypeAhead: true,\n    disallowEmptySelection: true,\n    ref: inputRef\n  });\n\n  // For textfield specific keydown operations\n  let onKeyDown = (e: KeyboardEvent) => {\n    switch (e.key) {\n      case 'Enter':\n      case 'Tab':\n        state.commit();\n        break;\n      case 'Escape':\n        state.close();\n        break;\n      case 'ArrowDown':\n        state.open('first');\n        break;\n      case 'ArrowUp':\n        state.open('last');\n        break;\n      case 'ArrowLeft':\n      case 'ArrowRight':\n        state.selectionManager.setFocusedKey(null);\n        break;\n    }\n  };\n\n  let onBlur = (e: FocusEvent) => {\n    // Ignore blur if focused moved to the button or into the popover.\n    if (e.relatedTarget === buttonRef.current || popoverRef.current?.contains(e.relatedTarget as HTMLElement)) {\n      return;\n    }\n\n    if (props.onBlur) {\n      props.onBlur(e);\n    }\n\n    state.setFocused(false);\n  };\n\n  let onFocus = (e: FocusEvent) => {\n    if (state.isFocused) {\n      return;\n    }\n\n    if (props.onFocus) {\n      props.onFocus(e);\n    }\n\n    state.setFocused(true);\n  };\n\n  let {labelProps, inputProps} = useTextField({\n    ...props,\n    onChange: state.setInputValue,\n    onKeyDown: !isReadOnly && chain(state.isOpen && collectionProps.onKeyDownCapture, onKeyDown),\n    onBlur,\n    value: state.inputValue,\n    onFocus,\n    autoComplete: 'off'\n  }, inputRef);\n\n  // Press handlers for the ComboBox button\n  let onPress = (e: PressEvent) => {\n    if (e.pointerType === 'touch') {\n      // Focus the input field in case it isn't focused yet\n      inputRef.current.focus();\n      state.toggle();\n    }\n  };\n\n  let onPressStart = (e: PressEvent) => {\n    if (e.pointerType !== 'touch') {\n      inputRef.current.focus();\n      state.toggle((e.pointerType === 'keyboard' || e.pointerType === 'virtual') ? 'first' : null);\n    }\n  };\n\n  let triggerLabelProps = useLabels({\n    id: menuTriggerProps.id,\n    'aria-label': formatMessage('buttonLabel'),\n    'aria-labelledby': props['aria-labelledby'] || labelProps.id\n  });\n\n  let listBoxProps = useLabels({\n    id: menuProps.id,\n    'aria-label': formatMessage('listboxLabel'),\n    'aria-labelledby': props['aria-labelledby'] || labelProps.id\n  });\n\n  // If a touch happens on direct center of ComboBox input, might be virtual click from iPad so open ComboBox menu\n  let lastEventTime = useRef(0);\n  let onTouchEnd = (e: TouchEvent) => {\n    if (isDisabled || isReadOnly) {\n      return;\n    }\n\n    // Sometimes VoiceOver on iOS fires two touchend events in quick succession. Ignore the second one.\n    if (e.timeStamp - lastEventTime.current < 500) {\n      e.preventDefault();\n      inputRef.current.focus();\n      return;\n    }\n\n    let rect = (e.target as HTMLElement).getBoundingClientRect();\n    let touch = e.changedTouches[0];\n\n    let centerX = Math.ceil(rect.left + .5 * rect.width);\n    let centerY = Math.ceil(rect.top + .5 * rect.height);\n\n    if (touch.clientX === centerX && touch.clientY === centerY) {\n      e.preventDefault();\n      inputRef.current.focus();\n      state.toggle();\n\n      lastEventTime.current = e.timeStamp;\n    }\n  };\n\n  // VoiceOver has issues with announcing aria-activedescendant properly on change\n  // (especially on iOS). We use a live region announcer to announce focus changes\n  // manually. In addition, section titles are announced when navigating into a new section.\n  let focusedItem = state.selectionManager.focusedKey != null && state.isOpen\n    ? state.collection.getItem(state.selectionManager.focusedKey)\n    : undefined;\n  let sectionKey = focusedItem?.parentKey ?? null;\n  let itemKey = state.selectionManager.focusedKey ?? null;\n  let lastSection = useRef(sectionKey);\n  let lastItem = useRef(itemKey);\n  useEffect(() => {\n    if (isAppleDevice() && focusedItem != null && itemKey !== lastItem.current) {\n      let isSelected = state.selectionManager.isSelected(itemKey);\n      let section = sectionKey != null ? state.collection.getItem(sectionKey) : null;\n      let sectionTitle = section?.['aria-label'] || (typeof section?.rendered === 'string' ? section.rendered : '') || '';\n\n      let announcement = formatMessage('focusAnnouncement', {\n        isGroupChange: section && sectionKey !== lastSection.current,\n        groupTitle: sectionTitle,\n        groupCount: section ? [...section.childNodes].length : 0,\n        optionText: focusedItem['aria-label'] || focusedItem.textValue || '',\n        isSelected\n      });\n\n      announce(announcement);\n    }\n\n    lastSection.current = sectionKey;\n    lastItem.current = itemKey;\n  });\n\n  // Announce the number of available suggestions when it changes\n  let optionCount = getItemCount(state.collection);\n  let lastSize = useRef(optionCount);\n  let lastOpen = useRef(state.isOpen);\n  useEffect(() => {\n    // Only announce the number of options available when the menu opens if there is no\n    // focused item, otherwise screen readers will typically read e.g. \"1 of 6\".\n    // The exception is VoiceOver since this isn't included in the message above.\n    let didOpenWithoutFocusedItem =\n      state.isOpen !== lastOpen.current &&\n      (state.selectionManager.focusedKey == null || isAppleDevice());\n\n    if (state.isOpen && (didOpenWithoutFocusedItem || optionCount !== lastSize.current)) {\n      let announcement = formatMessage('countAnnouncement', {optionCount});\n      announce(announcement);\n    }\n\n    lastSize.current = optionCount;\n    lastOpen.current = state.isOpen;\n  });\n\n  // Announce when a selection occurs for VoiceOver. Other screen readers typically do this automatically.\n  let lastSelectedKey = useRef(state.selectedKey);\n  useEffect(() => {\n    if (isAppleDevice() && state.isFocused && state.selectedItem && state.selectedKey !== lastSelectedKey.current) {\n      let optionText = state.selectedItem['aria-label'] || state.selectedItem.textValue || '';\n      let announcement = formatMessage('selectedAnnouncement', {optionText});\n      announce(announcement);\n    }\n\n    lastSelectedKey.current = state.selectedKey;\n  });\n\n  useEffect(() => {\n    if (state.isOpen) {\n      return ariaHideOutside([inputRef.current, popoverRef.current]);\n    }\n  }, [state.isOpen, inputRef, popoverRef]);\n\n  return {\n    labelProps,\n    buttonProps: {\n      ...menuTriggerProps,\n      ...triggerLabelProps,\n      excludeFromTabOrder: true,\n      onPress,\n      onPressStart\n    },\n    inputProps: mergeProps(inputProps, {\n      role: 'combobox',\n      'aria-expanded': menuTriggerProps['aria-expanded'],\n      'aria-controls': state.isOpen ? menuProps.id : undefined,\n      // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n      'aria-autocomplete': 'list',\n      'aria-activedescendant': focusedItem ? getItemId(state, focusedItem.key) : undefined,\n      onTouchEnd,\n      // This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.\n      autoCorrect: 'off',\n      // This disable's the macOS Safari spell check auto corrections.\n      spellCheck: 'false'\n    }),\n    listBoxProps: mergeProps(menuProps, listBoxProps)\n  };\n}\n"]},"metadata":{},"sourceType":"module"}