@react-aria/combobox 3.8.5-nightly.4552 → 3.8.5-nightly.4558

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +1 -388
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +2 -389
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +1 -388
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/pt-BR.mjs +1 -1
  34. package/dist/pt-PT.mjs +1 -1
  35. package/dist/ro-RO.mjs +1 -1
  36. package/dist/ru-RU.mjs +1 -1
  37. package/dist/sk-SK.mjs +1 -1
  38. package/dist/sl-SI.mjs +1 -1
  39. package/dist/sr-SP.mjs +1 -1
  40. package/dist/sv-SE.mjs +1 -1
  41. package/dist/tr-TR.mjs +1 -1
  42. package/dist/uk-UA.mjs +1 -1
  43. package/dist/useComboBox.main.js +292 -0
  44. package/dist/useComboBox.main.js.map +1 -0
  45. package/dist/useComboBox.mjs +287 -0
  46. package/dist/useComboBox.module.js +287 -0
  47. package/dist/useComboBox.module.js.map +1 -0
  48. package/dist/zh-CN.mjs +1 -1
  49. package/dist/zh-TW.mjs +1 -1
  50. package/package.json +16 -16
@@ -0,0 +1,292 @@
1
+ var $8d1e5da058b86bb9$exports = require("./intlStrings.main.js");
2
+ var $BGXP4$reactarialiveannouncer = require("@react-aria/live-announcer");
3
+ var $BGXP4$reactariaoverlays = require("@react-aria/overlays");
4
+ var $BGXP4$reactarialistbox = require("@react-aria/listbox");
5
+ var $BGXP4$reactariautils = require("@react-aria/utils");
6
+ var $BGXP4$react = require("react");
7
+ var $BGXP4$reactstatelycollections = require("@react-stately/collections");
8
+ var $BGXP4$reactariaselection = require("@react-aria/selection");
9
+ var $BGXP4$reactstatelyform = require("@react-stately/form");
10
+ var $BGXP4$reactariai18n = require("@react-aria/i18n");
11
+ var $BGXP4$reactariamenu = require("@react-aria/menu");
12
+ var $BGXP4$reactariatextfield = require("@react-aria/textfield");
13
+
14
+
15
+ function $parcel$interopDefault(a) {
16
+ return a && a.__esModule ? a.default : a;
17
+ }
18
+
19
+ function $parcel$export(e, n, v, s) {
20
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
21
+ }
22
+
23
+ $parcel$export(module.exports, "useComboBox", () => $242452271d1e4c0e$export$8c18d1b4f7232bbf);
24
+ /*
25
+ * Copyright 2020 Adobe. All rights reserved.
26
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
27
+ * you may not use this file except in compliance with the License. You may obtain a copy
28
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software distributed under
31
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
32
+ * OF ANY KIND, either express or implied. See the License for the specific language
33
+ * governing permissions and limitations under the License.
34
+ */
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ function $242452271d1e4c0e$export$8c18d1b4f7232bbf(props, state) {
47
+ let { buttonRef: buttonRef, popoverRef: popoverRef, inputRef: inputRef, listBoxRef: listBoxRef, keyboardDelegate: keyboardDelegate, shouldFocusWrap: // completionMode = 'suggest',
48
+ shouldFocusWrap, isReadOnly: isReadOnly, isDisabled: isDisabled } = props;
49
+ let stringFormatter = (0, $BGXP4$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($8d1e5da058b86bb9$exports))), "@react-aria/combobox");
50
+ let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $BGXP4$reactariamenu.useMenuTrigger)({
51
+ type: "listbox",
52
+ isDisabled: isDisabled || isReadOnly
53
+ }, state, buttonRef);
54
+ // Set listbox id so it can be used when calling getItemId later
55
+ (0, $BGXP4$reactarialistbox.listData).set(state, {
56
+ id: menuProps.id
57
+ });
58
+ // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
59
+ // When virtualized, the layout object will be passed in as a prop and override this.
60
+ let delegate = (0, $BGXP4$react.useMemo)(()=>keyboardDelegate || new (0, $BGXP4$reactariaselection.ListKeyboardDelegate)(state.collection, state.disabledKeys, listBoxRef), [
61
+ keyboardDelegate,
62
+ state.collection,
63
+ state.disabledKeys,
64
+ listBoxRef
65
+ ]);
66
+ // Use useSelectableCollection to get the keyboard handlers to apply to the textfield
67
+ let { collectionProps: collectionProps } = (0, $BGXP4$reactariaselection.useSelectableCollection)({
68
+ selectionManager: state.selectionManager,
69
+ keyboardDelegate: delegate,
70
+ disallowTypeAhead: true,
71
+ disallowEmptySelection: true,
72
+ shouldFocusWrap: shouldFocusWrap,
73
+ ref: inputRef,
74
+ // Prevent item scroll behavior from being applied here, should be handled in the user's Popover + ListBox component
75
+ isVirtualized: true
76
+ });
77
+ let router = (0, $BGXP4$reactariautils.useRouter)();
78
+ // For textfield specific keydown operations
79
+ let onKeyDown = (e)=>{
80
+ switch(e.key){
81
+ case "Enter":
82
+ case "Tab":
83
+ // Prevent form submission if menu is open since we may be selecting a option
84
+ if (state.isOpen && e.key === "Enter") e.preventDefault();
85
+ // If the focused item is a link, trigger opening it. Items that are links are not selectable.
86
+ if (state.isOpen && state.selectionManager.focusedKey != null && state.selectionManager.isLink(state.selectionManager.focusedKey)) {
87
+ if (e.key === "Enter") {
88
+ let item = listBoxRef.current.querySelector(`[data-key="${CSS.escape(state.selectionManager.focusedKey.toString())}"]`);
89
+ if (item instanceof HTMLAnchorElement) {
90
+ let collectionItem = state.collection.getItem(state.selectionManager.focusedKey);
91
+ router.open(item, e, collectionItem.props.href, collectionItem.props.routerOptions);
92
+ }
93
+ }
94
+ state.close();
95
+ } else state.commit();
96
+ break;
97
+ case "Escape":
98
+ if (state.selectedKey !== null || state.inputValue === "" || props.allowsCustomValue) e.continuePropagation();
99
+ state.revert();
100
+ break;
101
+ case "ArrowDown":
102
+ state.open("first", "manual");
103
+ break;
104
+ case "ArrowUp":
105
+ state.open("last", "manual");
106
+ break;
107
+ case "ArrowLeft":
108
+ case "ArrowRight":
109
+ state.selectionManager.setFocusedKey(null);
110
+ break;
111
+ }
112
+ };
113
+ let onBlur = (e)=>{
114
+ var _popoverRef_current;
115
+ let blurFromButton = (buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) && buttonRef.current === e.relatedTarget;
116
+ let blurIntoPopover = (_popoverRef_current = popoverRef.current) === null || _popoverRef_current === void 0 ? void 0 : _popoverRef_current.contains(e.relatedTarget);
117
+ // Ignore blur if focused moved to the button(if exists) or into the popover.
118
+ if (blurFromButton || blurIntoPopover) return;
119
+ if (props.onBlur) props.onBlur(e);
120
+ state.setFocused(false);
121
+ };
122
+ let onFocus = (e)=>{
123
+ if (state.isFocused) return;
124
+ if (props.onFocus) props.onFocus(e);
125
+ state.setFocused(true);
126
+ };
127
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
128
+ let { labelProps: labelProps, inputProps: inputProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $BGXP4$reactariatextfield.useTextField)({
129
+ ...props,
130
+ onChange: state.setInputValue,
131
+ onKeyDown: !isReadOnly ? (0, $BGXP4$reactariautils.chain)(state.isOpen && collectionProps.onKeyDown, onKeyDown, props.onKeyDown) : props.onKeyDown,
132
+ onBlur: onBlur,
133
+ value: state.inputValue,
134
+ onFocus: onFocus,
135
+ autoComplete: "off",
136
+ validate: undefined,
137
+ [(0, $BGXP4$reactstatelyform.privateValidationStateProp)]: state
138
+ }, inputRef);
139
+ // Press handlers for the ComboBox button
140
+ let onPress = (e)=>{
141
+ if (e.pointerType === "touch") {
142
+ // Focus the input field in case it isn't focused yet
143
+ inputRef.current.focus();
144
+ state.toggle(null, "manual");
145
+ }
146
+ };
147
+ let onPressStart = (e)=>{
148
+ if (e.pointerType !== "touch") {
149
+ inputRef.current.focus();
150
+ state.toggle(e.pointerType === "keyboard" || e.pointerType === "virtual" ? "first" : null, "manual");
151
+ }
152
+ };
153
+ let triggerLabelProps = (0, $BGXP4$reactariautils.useLabels)({
154
+ id: menuTriggerProps.id,
155
+ "aria-label": stringFormatter.format("buttonLabel"),
156
+ "aria-labelledby": props["aria-labelledby"] || labelProps.id
157
+ });
158
+ let listBoxProps = (0, $BGXP4$reactariautils.useLabels)({
159
+ id: menuProps.id,
160
+ "aria-label": stringFormatter.format("listboxLabel"),
161
+ "aria-labelledby": props["aria-labelledby"] || labelProps.id
162
+ });
163
+ // If a touch happens on direct center of ComboBox input, might be virtual click from iPad so open ComboBox menu
164
+ let lastEventTime = (0, $BGXP4$react.useRef)(0);
165
+ let onTouchEnd = (e)=>{
166
+ if (isDisabled || isReadOnly) return;
167
+ // Sometimes VoiceOver on iOS fires two touchend events in quick succession. Ignore the second one.
168
+ if (e.timeStamp - lastEventTime.current < 500) {
169
+ e.preventDefault();
170
+ inputRef.current.focus();
171
+ return;
172
+ }
173
+ let rect = e.target.getBoundingClientRect();
174
+ let touch = e.changedTouches[0];
175
+ let centerX = Math.ceil(rect.left + .5 * rect.width);
176
+ let centerY = Math.ceil(rect.top + .5 * rect.height);
177
+ if (touch.clientX === centerX && touch.clientY === centerY) {
178
+ e.preventDefault();
179
+ inputRef.current.focus();
180
+ state.toggle(null, "manual");
181
+ lastEventTime.current = e.timeStamp;
182
+ }
183
+ };
184
+ // VoiceOver has issues with announcing aria-activedescendant properly on change
185
+ // (especially on iOS). We use a live region announcer to announce focus changes
186
+ // manually. In addition, section titles are announced when navigating into a new section.
187
+ let focusedItem = state.selectionManager.focusedKey != null && state.isOpen ? state.collection.getItem(state.selectionManager.focusedKey) : undefined;
188
+ var _focusedItem_parentKey;
189
+ let sectionKey = (_focusedItem_parentKey = focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.parentKey) !== null && _focusedItem_parentKey !== void 0 ? _focusedItem_parentKey : null;
190
+ var _state_selectionManager_focusedKey;
191
+ let itemKey = (_state_selectionManager_focusedKey = state.selectionManager.focusedKey) !== null && _state_selectionManager_focusedKey !== void 0 ? _state_selectionManager_focusedKey : null;
192
+ let lastSection = (0, $BGXP4$react.useRef)(sectionKey);
193
+ let lastItem = (0, $BGXP4$react.useRef)(itemKey);
194
+ (0, $BGXP4$react.useEffect)(()=>{
195
+ if ((0, $BGXP4$reactariautils.isAppleDevice)() && focusedItem != null && itemKey !== lastItem.current) {
196
+ let isSelected = state.selectionManager.isSelected(itemKey);
197
+ let section = sectionKey != null ? state.collection.getItem(sectionKey) : null;
198
+ let sectionTitle = (section === null || section === void 0 ? void 0 : section["aria-label"]) || (typeof (section === null || section === void 0 ? void 0 : section.rendered) === "string" ? section.rendered : "") || "";
199
+ let announcement = stringFormatter.format("focusAnnouncement", {
200
+ isGroupChange: section && sectionKey !== lastSection.current,
201
+ groupTitle: sectionTitle,
202
+ groupCount: section ? [
203
+ ...(0, $BGXP4$reactstatelycollections.getChildNodes)(section, state.collection)
204
+ ].length : 0,
205
+ optionText: focusedItem["aria-label"] || focusedItem.textValue || "",
206
+ isSelected: isSelected
207
+ });
208
+ (0, $BGXP4$reactarialiveannouncer.announce)(announcement);
209
+ }
210
+ lastSection.current = sectionKey;
211
+ lastItem.current = itemKey;
212
+ });
213
+ // Announce the number of available suggestions when it changes
214
+ let optionCount = (0, $BGXP4$reactstatelycollections.getItemCount)(state.collection);
215
+ let lastSize = (0, $BGXP4$react.useRef)(optionCount);
216
+ let lastOpen = (0, $BGXP4$react.useRef)(state.isOpen);
217
+ (0, $BGXP4$react.useEffect)(()=>{
218
+ // Only announce the number of options available when the menu opens if there is no
219
+ // focused item, otherwise screen readers will typically read e.g. "1 of 6".
220
+ // The exception is VoiceOver since this isn't included in the message above.
221
+ let didOpenWithoutFocusedItem = state.isOpen !== lastOpen.current && (state.selectionManager.focusedKey == null || (0, $BGXP4$reactariautils.isAppleDevice)());
222
+ if (state.isOpen && (didOpenWithoutFocusedItem || optionCount !== lastSize.current)) {
223
+ let announcement = stringFormatter.format("countAnnouncement", {
224
+ optionCount: optionCount
225
+ });
226
+ (0, $BGXP4$reactarialiveannouncer.announce)(announcement);
227
+ }
228
+ lastSize.current = optionCount;
229
+ lastOpen.current = state.isOpen;
230
+ });
231
+ // Announce when a selection occurs for VoiceOver. Other screen readers typically do this automatically.
232
+ let lastSelectedKey = (0, $BGXP4$react.useRef)(state.selectedKey);
233
+ (0, $BGXP4$react.useEffect)(()=>{
234
+ if ((0, $BGXP4$reactariautils.isAppleDevice)() && state.isFocused && state.selectedItem && state.selectedKey !== lastSelectedKey.current) {
235
+ let optionText = state.selectedItem["aria-label"] || state.selectedItem.textValue || "";
236
+ let announcement = stringFormatter.format("selectedAnnouncement", {
237
+ optionText: optionText
238
+ });
239
+ (0, $BGXP4$reactarialiveannouncer.announce)(announcement);
240
+ }
241
+ lastSelectedKey.current = state.selectedKey;
242
+ });
243
+ (0, $BGXP4$react.useEffect)(()=>{
244
+ if (state.isOpen) return (0, $BGXP4$reactariaoverlays.ariaHideOutside)([
245
+ inputRef.current,
246
+ popoverRef.current
247
+ ]);
248
+ }, [
249
+ state.isOpen,
250
+ inputRef,
251
+ popoverRef
252
+ ]);
253
+ return {
254
+ labelProps: labelProps,
255
+ buttonProps: {
256
+ ...menuTriggerProps,
257
+ ...triggerLabelProps,
258
+ excludeFromTabOrder: true,
259
+ onPress: onPress,
260
+ onPressStart: onPressStart,
261
+ isDisabled: isDisabled || isReadOnly
262
+ },
263
+ inputProps: (0, $BGXP4$reactariautils.mergeProps)(inputProps, {
264
+ role: "combobox",
265
+ "aria-expanded": menuTriggerProps["aria-expanded"],
266
+ "aria-controls": state.isOpen ? menuProps.id : undefined,
267
+ // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
268
+ "aria-autocomplete": "list",
269
+ "aria-activedescendant": focusedItem ? (0, $BGXP4$reactarialistbox.getItemId)(state, focusedItem.key) : undefined,
270
+ onTouchEnd: onTouchEnd,
271
+ // This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.
272
+ autoCorrect: "off",
273
+ // This disable's the macOS Safari spell check auto corrections.
274
+ spellCheck: "false"
275
+ }),
276
+ listBoxProps: (0, $BGXP4$reactariautils.mergeProps)(menuProps, listBoxProps, {
277
+ autoFocus: state.focusStrategy,
278
+ shouldUseVirtualFocus: true,
279
+ shouldSelectOnPressUp: true,
280
+ shouldFocusOnHover: true,
281
+ linkBehavior: "selection"
282
+ }),
283
+ descriptionProps: descriptionProps,
284
+ errorMessageProps: errorMessageProps,
285
+ isInvalid: isInvalid,
286
+ validationErrors: validationErrors,
287
+ validationDetails: validationDetails
288
+ };
289
+ }
290
+
291
+
292
+ //# sourceMappingURL=useComboBox.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;;;AAsDM,SAAS,0CAAe,KAA6B,EAAE,KAAuB;IACnF,IAAI,aACF,S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,MAAM,YAAY,IAAI,MAAM,WAAW,KAAK,gBAAgB,OAAO,EAAE;YAC7G,IAAI,aAAa,MAAM,YAAY,CAAC,aAAa,IAAI,MAAM,YAAY,CAAC,SAAS,IAAI;YACrF,IAAI,eAAe,gBAAgB,MAAM,CAAC,wBAAwB;4BAAC;YAAU;YAC7E,CAAA,GAAA,sCAAO,EAAE;QACX;QAEA,gBAAgB,OAAO,GAAG,MAAM,WAAW;IAC7C;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,MAAM,EACd,OAAO,CAAA,GAAA,wCAAc,EAAE;YAAC,SAAS,OAAO;YAAE,WAAW,OAAO;SAAC;IAEjE,GAAG;QAAC,MAAM,MAAM;QAAE;QAAU;KAAW;IAEvC,OAAO;oBACL;QACA,aAAa;YACX,GAAG,gBAAgB;YACnB,GAAG,iBAAiB;YACpB,qBAAqB;qBACrB;0BACA;YACA,YAAY,cAAc;QAC5B;QACA,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;YACjC,MAAM;YACN,iBAAiB,gBAAgB,CAAC,gBAAgB;YAClD,iBAAiB,MAAM,MAAM,GAAG,UAAU,EAAE,GAAG;YAC/C,mFAAmF;YACnF,qBAAqB;YACrB,yBAAyB,cAAc,CAAA,GAAA,iCAAQ,EAAE,OAAO,YAAY,GAAG,IAAI;wBAC3E;YACA,kGAAkG;YAClG,aAAa;YACb,gEAAgE;YAChE,YAAY;QACd;QACA,cAAc,CAAA,GAAA,gCAAS,EAAE,WAAW,cAAc;YAChD,WAAW,MAAM,aAAa;YAC9B,uBAAuB;YACvB,uBAAuB;YACvB,oBAAoB;YACpB,cAAc;QAChB;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/combobox/src/useComboBox.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 {announce} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaComboBoxProps} from '@react-types/combobox';\nimport {ariaHideOutside} from '@react-aria/overlays';\nimport {AriaListBoxOptions, getItemId, listData} from '@react-aria/listbox';\nimport {BaseEvent, DOMAttributes, KeyboardDelegate, PressEvent, RouterOptions, ValidationResult} from '@react-types/shared';\nimport {chain, isAppleDevice, mergeProps, useLabels, useRouter} from '@react-aria/utils';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {FocusEvent, InputHTMLAttributes, KeyboardEvent, RefObject, TouchEvent, useEffect, useMemo, useRef} from 'react';\nimport {getChildNodes, getItemCount} from '@react-stately/collections';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ListKeyboardDelegate, useSelectableCollection} from '@react-aria/selection';\nimport {privateValidationStateProp} from '@react-stately/form';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMenuTrigger} from '@react-aria/menu';\nimport {useTextField} from '@react-aria/textfield';\n\nexport interface AriaComboBoxOptions<T> extends Omit<AriaComboBoxProps<T>, 'children'> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<Element>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement>,\n /** The ref for the optional list box popup trigger button. */\n buttonRef?: RefObject<Element>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate\n}\n\nexport interface ComboBoxAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the combo box input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the list box, to be passed to [useListBox](useListBox.html). */\n listBoxProps: AriaListBoxOptions<T>,\n /** Props for the optional trigger button, to be passed to [useButton](useButton.html). */\n buttonProps: AriaButtonProps,\n /** Props for the combo box description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the combo box error message element, if any. */\n errorMessageProps: DOMAttributes\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: AriaComboBoxOptions<T>, state: ComboBoxState<T>): ComboBoxAria<T> {\n let {\n buttonRef,\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n // completionMode = 'suggest',\n shouldFocusWrap,\n isReadOnly,\n isDisabled\n } = props;\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/combobox');\n let {menuTriggerProps, menuProps} = useMenuTrigger<T>(\n {\n type: 'listbox',\n isDisabled: isDisabled || isReadOnly\n },\n state,\n buttonRef\n );\n\n // Set listbox id so it can be used when calling getItemId later\n listData.set(state, {id: 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 shouldFocusWrap,\n ref: inputRef,\n // Prevent item scroll behavior from being applied here, should be handled in the user's Popover + ListBox component\n isVirtualized: true\n });\n\n let router = useRouter();\n\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<KeyboardEvent<any>>) => {\n switch (e.key) {\n case 'Enter':\n case 'Tab':\n // Prevent form submission if menu is open since we may be selecting a option\n if (state.isOpen && e.key === 'Enter') {\n e.preventDefault();\n }\n\n // If the focused item is a link, trigger opening it. Items that are links are not selectable.\n if (state.isOpen && state.selectionManager.focusedKey != null && state.selectionManager.isLink(state.selectionManager.focusedKey)) {\n if (e.key === 'Enter') {\n let item = listBoxRef.current.querySelector(`[data-key=\"${CSS.escape(state.selectionManager.focusedKey.toString())}\"]`);\n if (item instanceof HTMLAnchorElement) {\n let collectionItem = state.collection.getItem(state.selectionManager.focusedKey);\n router.open(item, e, collectionItem.props.href, collectionItem.props.routerOptions as RouterOptions);\n }\n }\n\n state.close();\n } else {\n state.commit();\n }\n break;\n case 'Escape':\n if (\n state.selectedKey !== null ||\n state.inputValue === '' ||\n props.allowsCustomValue\n ) {\n e.continuePropagation();\n }\n state.revert();\n break;\n case 'ArrowDown':\n state.open('first', 'manual');\n break;\n case 'ArrowUp':\n state.open('last', 'manual');\n break;\n case 'ArrowLeft':\n case 'ArrowRight':\n state.selectionManager.setFocusedKey(null);\n break;\n }\n };\n\n let onBlur = (e: FocusEvent<HTMLInputElement>) => {\n let blurFromButton = buttonRef?.current && buttonRef.current === e.relatedTarget;\n let blurIntoPopover = popoverRef.current?.contains(e.relatedTarget);\n // Ignore blur if focused moved to the button(if exists) or into the popover.\n if (blurFromButton || blurIntoPopover) {\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<HTMLInputElement>) => {\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 {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, inputProps, descriptionProps, errorMessageProps} = useTextField({\n ...props,\n onChange: state.setInputValue,\n onKeyDown: !isReadOnly ? chain(state.isOpen && collectionProps.onKeyDown, onKeyDown, props.onKeyDown) : props.onKeyDown,\n onBlur,\n value: state.inputValue,\n onFocus,\n autoComplete: 'off',\n validate: undefined,\n [privateValidationStateProp]: state\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(null, 'manual');\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, 'manual');\n }\n };\n\n let triggerLabelProps = useLabels({\n id: menuTriggerProps.id,\n 'aria-label': stringFormatter.format('buttonLabel'),\n 'aria-labelledby': props['aria-labelledby'] || labelProps.id\n });\n\n let listBoxProps = useLabels({\n id: menuProps.id,\n 'aria-label': stringFormatter.format('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 Element).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(null, 'manual');\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 = stringFormatter.format('focusAnnouncement', {\n isGroupChange: section && sectionKey !== lastSection.current,\n groupTitle: sectionTitle,\n groupCount: section ? [...getChildNodes(section, state.collection)].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 = stringFormatter.format('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 = stringFormatter.format('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 isDisabled: isDisabled || isReadOnly\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 autoFocus: state.focusStrategy,\n shouldUseVirtualFocus: true,\n shouldSelectOnPressUp: true,\n shouldFocusOnHover: true,\n linkBehavior: 'selection' as const\n }),\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useComboBox.main.js.map"}
@@ -0,0 +1,287 @@
1
+ import $dShfP$intlStringsmodulejs from "./intlStrings.mjs";
2
+ import {announce as $dShfP$announce} from "@react-aria/live-announcer";
3
+ import {ariaHideOutside as $dShfP$ariaHideOutside} from "@react-aria/overlays";
4
+ import {listData as $dShfP$listData, getItemId as $dShfP$getItemId} from "@react-aria/listbox";
5
+ import {useRouter as $dShfP$useRouter, chain as $dShfP$chain, useLabels as $dShfP$useLabels, isAppleDevice as $dShfP$isAppleDevice, mergeProps as $dShfP$mergeProps} from "@react-aria/utils";
6
+ import {useMemo as $dShfP$useMemo, useRef as $dShfP$useRef, useEffect as $dShfP$useEffect} from "react";
7
+ import {getChildNodes as $dShfP$getChildNodes, getItemCount as $dShfP$getItemCount} from "@react-stately/collections";
8
+ import {ListKeyboardDelegate as $dShfP$ListKeyboardDelegate, useSelectableCollection as $dShfP$useSelectableCollection} from "@react-aria/selection";
9
+ import {privateValidationStateProp as $dShfP$privateValidationStateProp} from "@react-stately/form";
10
+ import {useLocalizedStringFormatter as $dShfP$useLocalizedStringFormatter} from "@react-aria/i18n";
11
+ import {useMenuTrigger as $dShfP$useMenuTrigger} from "@react-aria/menu";
12
+ import {useTextField as $dShfP$useTextField} from "@react-aria/textfield";
13
+
14
+
15
+ function $parcel$interopDefault(a) {
16
+ return a && a.__esModule ? a.default : a;
17
+ }
18
+ /*
19
+ * Copyright 2020 Adobe. All rights reserved.
20
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
21
+ * you may not use this file except in compliance with the License. You may obtain a copy
22
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
23
+ *
24
+ * Unless required by applicable law or agreed to in writing, software distributed under
25
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
26
+ * OF ANY KIND, either express or implied. See the License for the specific language
27
+ * governing permissions and limitations under the License.
28
+ */
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+ function $c350ade66beef0af$export$8c18d1b4f7232bbf(props, state) {
41
+ let { buttonRef: buttonRef, popoverRef: popoverRef, inputRef: inputRef, listBoxRef: listBoxRef, keyboardDelegate: keyboardDelegate, shouldFocusWrap: // completionMode = 'suggest',
42
+ shouldFocusWrap, isReadOnly: isReadOnly, isDisabled: isDisabled } = props;
43
+ let stringFormatter = (0, $dShfP$useLocalizedStringFormatter)((0, ($parcel$interopDefault($dShfP$intlStringsmodulejs))), "@react-aria/combobox");
44
+ let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $dShfP$useMenuTrigger)({
45
+ type: "listbox",
46
+ isDisabled: isDisabled || isReadOnly
47
+ }, state, buttonRef);
48
+ // Set listbox id so it can be used when calling getItemId later
49
+ (0, $dShfP$listData).set(state, {
50
+ id: menuProps.id
51
+ });
52
+ // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
53
+ // When virtualized, the layout object will be passed in as a prop and override this.
54
+ let delegate = (0, $dShfP$useMemo)(()=>keyboardDelegate || new (0, $dShfP$ListKeyboardDelegate)(state.collection, state.disabledKeys, listBoxRef), [
55
+ keyboardDelegate,
56
+ state.collection,
57
+ state.disabledKeys,
58
+ listBoxRef
59
+ ]);
60
+ // Use useSelectableCollection to get the keyboard handlers to apply to the textfield
61
+ let { collectionProps: collectionProps } = (0, $dShfP$useSelectableCollection)({
62
+ selectionManager: state.selectionManager,
63
+ keyboardDelegate: delegate,
64
+ disallowTypeAhead: true,
65
+ disallowEmptySelection: true,
66
+ shouldFocusWrap: shouldFocusWrap,
67
+ ref: inputRef,
68
+ // Prevent item scroll behavior from being applied here, should be handled in the user's Popover + ListBox component
69
+ isVirtualized: true
70
+ });
71
+ let router = (0, $dShfP$useRouter)();
72
+ // For textfield specific keydown operations
73
+ let onKeyDown = (e)=>{
74
+ switch(e.key){
75
+ case "Enter":
76
+ case "Tab":
77
+ // Prevent form submission if menu is open since we may be selecting a option
78
+ if (state.isOpen && e.key === "Enter") e.preventDefault();
79
+ // If the focused item is a link, trigger opening it. Items that are links are not selectable.
80
+ if (state.isOpen && state.selectionManager.focusedKey != null && state.selectionManager.isLink(state.selectionManager.focusedKey)) {
81
+ if (e.key === "Enter") {
82
+ let item = listBoxRef.current.querySelector(`[data-key="${CSS.escape(state.selectionManager.focusedKey.toString())}"]`);
83
+ if (item instanceof HTMLAnchorElement) {
84
+ let collectionItem = state.collection.getItem(state.selectionManager.focusedKey);
85
+ router.open(item, e, collectionItem.props.href, collectionItem.props.routerOptions);
86
+ }
87
+ }
88
+ state.close();
89
+ } else state.commit();
90
+ break;
91
+ case "Escape":
92
+ if (state.selectedKey !== null || state.inputValue === "" || props.allowsCustomValue) e.continuePropagation();
93
+ state.revert();
94
+ break;
95
+ case "ArrowDown":
96
+ state.open("first", "manual");
97
+ break;
98
+ case "ArrowUp":
99
+ state.open("last", "manual");
100
+ break;
101
+ case "ArrowLeft":
102
+ case "ArrowRight":
103
+ state.selectionManager.setFocusedKey(null);
104
+ break;
105
+ }
106
+ };
107
+ let onBlur = (e)=>{
108
+ var _popoverRef_current;
109
+ let blurFromButton = (buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) && buttonRef.current === e.relatedTarget;
110
+ let blurIntoPopover = (_popoverRef_current = popoverRef.current) === null || _popoverRef_current === void 0 ? void 0 : _popoverRef_current.contains(e.relatedTarget);
111
+ // Ignore blur if focused moved to the button(if exists) or into the popover.
112
+ if (blurFromButton || blurIntoPopover) return;
113
+ if (props.onBlur) props.onBlur(e);
114
+ state.setFocused(false);
115
+ };
116
+ let onFocus = (e)=>{
117
+ if (state.isFocused) return;
118
+ if (props.onFocus) props.onFocus(e);
119
+ state.setFocused(true);
120
+ };
121
+ let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
122
+ let { labelProps: labelProps, inputProps: inputProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $dShfP$useTextField)({
123
+ ...props,
124
+ onChange: state.setInputValue,
125
+ onKeyDown: !isReadOnly ? (0, $dShfP$chain)(state.isOpen && collectionProps.onKeyDown, onKeyDown, props.onKeyDown) : props.onKeyDown,
126
+ onBlur: onBlur,
127
+ value: state.inputValue,
128
+ onFocus: onFocus,
129
+ autoComplete: "off",
130
+ validate: undefined,
131
+ [(0, $dShfP$privateValidationStateProp)]: state
132
+ }, inputRef);
133
+ // Press handlers for the ComboBox button
134
+ let onPress = (e)=>{
135
+ if (e.pointerType === "touch") {
136
+ // Focus the input field in case it isn't focused yet
137
+ inputRef.current.focus();
138
+ state.toggle(null, "manual");
139
+ }
140
+ };
141
+ let onPressStart = (e)=>{
142
+ if (e.pointerType !== "touch") {
143
+ inputRef.current.focus();
144
+ state.toggle(e.pointerType === "keyboard" || e.pointerType === "virtual" ? "first" : null, "manual");
145
+ }
146
+ };
147
+ let triggerLabelProps = (0, $dShfP$useLabels)({
148
+ id: menuTriggerProps.id,
149
+ "aria-label": stringFormatter.format("buttonLabel"),
150
+ "aria-labelledby": props["aria-labelledby"] || labelProps.id
151
+ });
152
+ let listBoxProps = (0, $dShfP$useLabels)({
153
+ id: menuProps.id,
154
+ "aria-label": stringFormatter.format("listboxLabel"),
155
+ "aria-labelledby": props["aria-labelledby"] || labelProps.id
156
+ });
157
+ // If a touch happens on direct center of ComboBox input, might be virtual click from iPad so open ComboBox menu
158
+ let lastEventTime = (0, $dShfP$useRef)(0);
159
+ let onTouchEnd = (e)=>{
160
+ if (isDisabled || isReadOnly) return;
161
+ // Sometimes VoiceOver on iOS fires two touchend events in quick succession. Ignore the second one.
162
+ if (e.timeStamp - lastEventTime.current < 500) {
163
+ e.preventDefault();
164
+ inputRef.current.focus();
165
+ return;
166
+ }
167
+ let rect = e.target.getBoundingClientRect();
168
+ let touch = e.changedTouches[0];
169
+ let centerX = Math.ceil(rect.left + .5 * rect.width);
170
+ let centerY = Math.ceil(rect.top + .5 * rect.height);
171
+ if (touch.clientX === centerX && touch.clientY === centerY) {
172
+ e.preventDefault();
173
+ inputRef.current.focus();
174
+ state.toggle(null, "manual");
175
+ lastEventTime.current = e.timeStamp;
176
+ }
177
+ };
178
+ // VoiceOver has issues with announcing aria-activedescendant properly on change
179
+ // (especially on iOS). We use a live region announcer to announce focus changes
180
+ // manually. In addition, section titles are announced when navigating into a new section.
181
+ let focusedItem = state.selectionManager.focusedKey != null && state.isOpen ? state.collection.getItem(state.selectionManager.focusedKey) : undefined;
182
+ var _focusedItem_parentKey;
183
+ let sectionKey = (_focusedItem_parentKey = focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.parentKey) !== null && _focusedItem_parentKey !== void 0 ? _focusedItem_parentKey : null;
184
+ var _state_selectionManager_focusedKey;
185
+ let itemKey = (_state_selectionManager_focusedKey = state.selectionManager.focusedKey) !== null && _state_selectionManager_focusedKey !== void 0 ? _state_selectionManager_focusedKey : null;
186
+ let lastSection = (0, $dShfP$useRef)(sectionKey);
187
+ let lastItem = (0, $dShfP$useRef)(itemKey);
188
+ (0, $dShfP$useEffect)(()=>{
189
+ if ((0, $dShfP$isAppleDevice)() && focusedItem != null && itemKey !== lastItem.current) {
190
+ let isSelected = state.selectionManager.isSelected(itemKey);
191
+ let section = sectionKey != null ? state.collection.getItem(sectionKey) : null;
192
+ let sectionTitle = (section === null || section === void 0 ? void 0 : section["aria-label"]) || (typeof (section === null || section === void 0 ? void 0 : section.rendered) === "string" ? section.rendered : "") || "";
193
+ let announcement = stringFormatter.format("focusAnnouncement", {
194
+ isGroupChange: section && sectionKey !== lastSection.current,
195
+ groupTitle: sectionTitle,
196
+ groupCount: section ? [
197
+ ...(0, $dShfP$getChildNodes)(section, state.collection)
198
+ ].length : 0,
199
+ optionText: focusedItem["aria-label"] || focusedItem.textValue || "",
200
+ isSelected: isSelected
201
+ });
202
+ (0, $dShfP$announce)(announcement);
203
+ }
204
+ lastSection.current = sectionKey;
205
+ lastItem.current = itemKey;
206
+ });
207
+ // Announce the number of available suggestions when it changes
208
+ let optionCount = (0, $dShfP$getItemCount)(state.collection);
209
+ let lastSize = (0, $dShfP$useRef)(optionCount);
210
+ let lastOpen = (0, $dShfP$useRef)(state.isOpen);
211
+ (0, $dShfP$useEffect)(()=>{
212
+ // Only announce the number of options available when the menu opens if there is no
213
+ // focused item, otherwise screen readers will typically read e.g. "1 of 6".
214
+ // The exception is VoiceOver since this isn't included in the message above.
215
+ let didOpenWithoutFocusedItem = state.isOpen !== lastOpen.current && (state.selectionManager.focusedKey == null || (0, $dShfP$isAppleDevice)());
216
+ if (state.isOpen && (didOpenWithoutFocusedItem || optionCount !== lastSize.current)) {
217
+ let announcement = stringFormatter.format("countAnnouncement", {
218
+ optionCount: optionCount
219
+ });
220
+ (0, $dShfP$announce)(announcement);
221
+ }
222
+ lastSize.current = optionCount;
223
+ lastOpen.current = state.isOpen;
224
+ });
225
+ // Announce when a selection occurs for VoiceOver. Other screen readers typically do this automatically.
226
+ let lastSelectedKey = (0, $dShfP$useRef)(state.selectedKey);
227
+ (0, $dShfP$useEffect)(()=>{
228
+ if ((0, $dShfP$isAppleDevice)() && state.isFocused && state.selectedItem && state.selectedKey !== lastSelectedKey.current) {
229
+ let optionText = state.selectedItem["aria-label"] || state.selectedItem.textValue || "";
230
+ let announcement = stringFormatter.format("selectedAnnouncement", {
231
+ optionText: optionText
232
+ });
233
+ (0, $dShfP$announce)(announcement);
234
+ }
235
+ lastSelectedKey.current = state.selectedKey;
236
+ });
237
+ (0, $dShfP$useEffect)(()=>{
238
+ if (state.isOpen) return (0, $dShfP$ariaHideOutside)([
239
+ inputRef.current,
240
+ popoverRef.current
241
+ ]);
242
+ }, [
243
+ state.isOpen,
244
+ inputRef,
245
+ popoverRef
246
+ ]);
247
+ return {
248
+ labelProps: labelProps,
249
+ buttonProps: {
250
+ ...menuTriggerProps,
251
+ ...triggerLabelProps,
252
+ excludeFromTabOrder: true,
253
+ onPress: onPress,
254
+ onPressStart: onPressStart,
255
+ isDisabled: isDisabled || isReadOnly
256
+ },
257
+ inputProps: (0, $dShfP$mergeProps)(inputProps, {
258
+ role: "combobox",
259
+ "aria-expanded": menuTriggerProps["aria-expanded"],
260
+ "aria-controls": state.isOpen ? menuProps.id : undefined,
261
+ // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
262
+ "aria-autocomplete": "list",
263
+ "aria-activedescendant": focusedItem ? (0, $dShfP$getItemId)(state, focusedItem.key) : undefined,
264
+ onTouchEnd: onTouchEnd,
265
+ // This disable's iOS's autocorrect suggestions, since the combo box provides its own suggestions.
266
+ autoCorrect: "off",
267
+ // This disable's the macOS Safari spell check auto corrections.
268
+ spellCheck: "false"
269
+ }),
270
+ listBoxProps: (0, $dShfP$mergeProps)(menuProps, listBoxProps, {
271
+ autoFocus: state.focusStrategy,
272
+ shouldUseVirtualFocus: true,
273
+ shouldSelectOnPressUp: true,
274
+ shouldFocusOnHover: true,
275
+ linkBehavior: "selection"
276
+ }),
277
+ descriptionProps: descriptionProps,
278
+ errorMessageProps: errorMessageProps,
279
+ isInvalid: isInvalid,
280
+ validationErrors: validationErrors,
281
+ validationDetails: validationDetails
282
+ };
283
+ }
284
+
285
+
286
+ export {$c350ade66beef0af$export$8c18d1b4f7232bbf as useComboBox};
287
+ //# sourceMappingURL=useComboBox.mjs.map