@react-aria/autocomplete 3.0.0-rc.2 → 3.0.0-rc.4

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.
package/dist/types.d.ts CHANGED
@@ -11,7 +11,7 @@ export interface SearchAutocompleteAria<T> extends ValidationResult {
11
11
  labelProps: DOMAttributes;
12
12
  /** Props for the search input element. */
13
13
  inputProps: InputHTMLAttributes<HTMLInputElement>;
14
- /** Props for the list box, to be passed to [useListBox](useListBox.html). */
14
+ /** Props for the list box, to be passed to `useListBox`. */
15
15
  listBoxProps: AriaListBoxOptions<T>;
16
16
  /** Props for the search input's clear button. */
17
17
  clearButtonProps: AriaButtonProps;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;AAsBA,wCAAwC,CAAC,CAAE,SAAQ,gBAAgB;IACjE,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAC1B,0CAA0C;IAC1C,UAAU,EAAE,oBAAoB,gBAAgB,CAAC,CAAC;IAClD,6EAA6E;IAC7E,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IACpC,iDAAiD;IACjD,gBAAgB,EAAE,eAAe,CAAC;IAClC,qEAAqE;IACrE,gBAAgB,EAAE,aAAa,CAAC;IAChC,uEAAuE;IACvE,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAED,+CAA+C,CAAC,CAAE,SAAQ,4BAA4B,CAAC,CAAC;IACtF,qCAAqC;IACrC,QAAQ,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC7C,wCAAwC;IACxC,UAAU,EAAE,UAAU,cAAc,GAAG,IAAI,CAAC,CAAC;IAC7C,gCAAgC;IAChC,UAAU,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IAC1C,6EAA6E;IAC7E,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAA;CAChC;AAED;;;;;GAKG;AACH,sCA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U,WAAW,GAAG,IAAI,CAAC,CAAC;IAC7C,+GAA+G;IAC/G,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,OAAO,CAAA;CAC3D;AAED;;;;;GAKG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,CAmVnH;ACrZD,YAAY,EAAC,2BAA2B,EAAC,MAAM,2BAA2B,CAAC","sources":["packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/useSearchAutocomplete.ts","packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/useAutocomplete.ts","packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/index.ts","packages/@react-aria/autocomplete/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2021 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 */\nexport {useSearchAutocomplete} from './useSearchAutocomplete';\nexport {useAutocomplete} from './useAutocomplete';\n\nexport type {AriaSearchAutocompleteOptions, SearchAutocompleteAria} from './useSearchAutocomplete';\nexport type {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nexport type {AriaAutocompleteProps, AriaAutocompleteOptions, AutocompleteAria, CollectionOptions, InputProps} from './useAutocomplete';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;;;;AAsBA,wCAAwC,CAAC,CAAE,SAAQ,gBAAgB;IACjE,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAC1B,0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CAAC,CAAE,SAAQ,iBAAiB;IACjE;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,OAAO,CAAC;IAE3E;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAC9B;AAED,yCAAyC,CAAC,CAAE,SAAQ,IAAI,CAAC,sBAAsB,CAAC,CAAC,EAAE,UAAU,CAAC;IAC5F,kDAAkD;IAClD,QAAQ,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC7C,kDAAkD;IAClD,aAAa,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAA;CAC7C;AAED,kCAAkC,CAAC;IACjC,sJAAsJ;IACtJ,UAAU,EAAE,UAAU,CAAC;IACvB,kGAAkG;IAClG,eAAe,EAAE,iBAAiB,CAAC;IACnC,+CAA+C;IAC/C,aAAa,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IAC7C,+GAA+G;IAC/G,MAAM,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,OAAO,CAAA;CAC3D;AAED;;;;;GAKG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,wBAAwB,CAAC,CAAC,EAAE,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,CAAC,CAAC,CAmWnH;ACraD,YAAY,EAAC,2BAA2B,EAAC,MAAM,2BAA2B,CAAC","sources":["packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/useSearchAutocomplete.ts","packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/useAutocomplete.ts","packages/@react-aria/autocomplete/src/packages/@react-aria/autocomplete/src/index.ts","packages/@react-aria/autocomplete/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2021 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 */\nexport {useSearchAutocomplete} from './useSearchAutocomplete';\nexport {useAutocomplete} from './useAutocomplete';\n\nexport type {AriaSearchAutocompleteOptions, SearchAutocompleteAria} from './useSearchAutocomplete';\nexport type {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nexport type {AriaAutocompleteProps, AriaAutocompleteOptions, AutocompleteAria, CollectionOptions, InputProps} from './useAutocomplete';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -33,21 +33,24 @@ $parcel$export(module.exports, "useAutocomplete", () => $d43aec1bf2be84e8$export
33
33
 
34
34
  function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
35
35
  let { inputRef: inputRef, collectionRef: collectionRef, filter: filter, disableAutoFocusFirst: disableAutoFocusFirst = false, disableVirtualFocus: disableVirtualFocus = false } = props;
36
- let collectionId = (0, $4yz2I$reactariautils.useSlotId)();
36
+ let collectionId = (0, $4yz2I$reactariautils.useId)();
37
37
  let timeout = (0, $4yz2I$react.useRef)(undefined);
38
38
  let delayNextActiveDescendant = (0, $4yz2I$react.useRef)(false);
39
39
  let queuedActiveDescendant = (0, $4yz2I$react.useRef)(null);
40
- let lastCollectionNode = (0, $4yz2I$react.useRef)(null);
41
40
  // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
42
41
  // moving focus back to the subtriggers
43
42
  let isMobileScreenReader = (0, $4yz2I$reactariainteractions.getInteractionModality)() === 'virtual' && ((0, $4yz2I$reactariautils.isIOS)() || (0, $4yz2I$reactariautils.isAndroid)());
44
- let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;
43
+ let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = (0, $4yz2I$react.useState)(!isMobileScreenReader && !disableVirtualFocus);
44
+ // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input
45
+ // since it isn't attached to a filterable collection (e.g. Tabs)
46
+ let [hasCollection, setHasCollection] = (0, $4yz2I$react.useState)(false);
45
47
  (0, $4yz2I$react.useEffect)(()=>{
46
48
  return ()=>clearTimeout(timeout.current);
47
49
  }, []);
48
- let updateActiveDescendant = (0, $4yz2I$reactariautils.useEffectEvent)((e)=>{
50
+ let updateActiveDescendantEvent = (0, $4yz2I$reactariautils.useEffectEvent)((e)=>{
49
51
  // Ensure input is focused if the user clicks on the collection directly.
50
- if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4yz2I$reactariautils.getActiveElement)((0, $4yz2I$reactariautils.getOwnerDocument)(inputRef.current)) !== inputRef.current) inputRef.current.focus();
52
+ // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options
53
+ if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4yz2I$reactariautils.getActiveElement)((0, $4yz2I$reactariautils.getOwnerDocument)(inputRef.current)) !== inputRef.current && (0, $4yz2I$reactariainteractions.getPointerType)() !== 'touch') inputRef.current.focus();
51
54
  let target = e.target;
52
55
  if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) return;
53
56
  clearTimeout(timeout.current);
@@ -71,27 +74,33 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
71
74
  }
72
75
  delayNextActiveDescendant.current = false;
73
76
  });
74
- let callbackRef = (0, $4yz2I$react.useCallback)((collectionNode)=>{
75
- var _lastCollectionNode_current;
76
- if (collectionNode != null) {
77
- var // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
78
- // of the letter you just typed. If we recieve another focus event then we clear the queued update
79
- // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
80
- // React 19's extra call of the callback ref in strict mode
81
- _lastCollectionNode_current1;
82
- (_lastCollectionNode_current1 = lastCollectionNode.current) === null || _lastCollectionNode_current1 === void 0 ? void 0 : _lastCollectionNode_current1.removeEventListener('focusin', updateActiveDescendant);
83
- lastCollectionNode.current = collectionNode;
84
- collectionNode.addEventListener('focusin', updateActiveDescendant);
85
- } else (_lastCollectionNode_current = lastCollectionNode.current) === null || _lastCollectionNode_current === void 0 ? void 0 : _lastCollectionNode_current.removeEventListener('focusin', updateActiveDescendant);
77
+ let [collectionNode, setCollectionNode] = (0, $4yz2I$react.useState)(null);
78
+ let callbackRef = (0, $4yz2I$react.useCallback)((node)=>{
79
+ setCollectionNode(node);
80
+ if (node != null) {
81
+ // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it
82
+ // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless
83
+ // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.
84
+ if (node.getAttribute('tabindex') != null) setShouldUseVirtualFocus(false);
85
+ setHasCollection(true);
86
+ } else setHasCollection(false);
87
+ }, []);
88
+ (0, $4yz2I$reactariautils.useLayoutEffect)(()=>{
89
+ if (collectionNode != null) // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
90
+ // of the letter you just typed. If we recieve another focus event then we clear the queued update
91
+ collectionNode.addEventListener('focusin', updateActiveDescendantEvent);
92
+ return ()=>{
93
+ collectionNode === null || collectionNode === void 0 ? void 0 : collectionNode.removeEventListener('focusin', updateActiveDescendantEvent);
94
+ };
86
95
  }, [
87
- updateActiveDescendant
96
+ collectionNode
88
97
  ]);
89
98
  // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
90
99
  let mergedCollectionRef = (0, $4yz2I$reactariautils.useObjectRef)((0, $4yz2I$react.useMemo)(()=>(0, $4yz2I$reactariautils.mergeRefs)(collectionRef, callbackRef), [
91
100
  collectionRef,
92
101
  callbackRef
93
102
  ]));
94
- let focusFirstItem = (0, $4yz2I$reactariautils.useEffectEvent)(()=>{
103
+ let focusFirstItem = (0, $4yz2I$react.useCallback)(()=>{
95
104
  var _collectionRef_current;
96
105
  delayNextActiveDescendant.current = true;
97
106
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new CustomEvent((0, $4yz2I$reactariautils.FOCUS_EVENT), {
@@ -101,8 +110,10 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
101
110
  focusStrategy: 'first'
102
111
  }
103
112
  }));
104
- });
105
- let clearVirtualFocus = (0, $4yz2I$reactariautils.useEffectEvent)((clearFocusKey)=>{
113
+ }, [
114
+ collectionRef
115
+ ]);
116
+ let clearVirtualFocus = (0, $4yz2I$react.useCallback)((clearFocusKey)=>{
106
117
  var _collectionRef_current;
107
118
  (0, $4yz2I$reactariafocus.moveVirtualFocus)((0, $4yz2I$reactariautils.getActiveElement)());
108
119
  queuedActiveDescendant.current = null;
@@ -117,7 +128,10 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
117
128
  clearTimeout(timeout.current);
118
129
  delayNextActiveDescendant.current = false;
119
130
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(clearFocusEvent);
120
- });
131
+ }, [
132
+ collectionRef,
133
+ state
134
+ ]);
121
135
  let lastInputType = (0, $4yz2I$react.useRef)('');
122
136
  (0, $4yz2I$reactariautils.useEvent)(inputRef, 'input', (e)=>{
123
137
  let { inputType: inputType } = e;
@@ -204,7 +218,7 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
204
218
  // Trigger click action on item when Enter key was pressed.
205
219
  if (focusedNodeId != null) {
206
220
  let item = document.getElementById(focusedNodeId);
207
- item === null || item === void 0 ? void 0 : item.click();
221
+ item === null || item === void 0 ? void 0 : item.dispatchEvent(new PointerEvent('click', e.nativeEvent));
208
222
  }
209
223
  break;
210
224
  }
@@ -231,9 +245,7 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
231
245
  return ()=>{
232
246
  document.removeEventListener('keyup', onKeyUpCapture, true);
233
247
  };
234
- }, [
235
- onKeyUpCapture
236
- ]);
248
+ }, []);
237
249
  let stringFormatter = (0, $4yz2I$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($fbc7b37667f52272$exports))), '@react-aria/autocomplete');
238
250
  let collectionProps = (0, $4yz2I$reactariautils.useLabels)({
239
251
  id: collectionId,
@@ -278,7 +290,7 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
278
290
  onBlur: onBlur,
279
291
  onFocus: onFocus
280
292
  };
281
- if (collectionId) inputProps = {
293
+ if (hasCollection) inputProps = {
282
294
  ...inputProps,
283
295
  ...shouldUseVirtualFocus && virtualFocusProps,
284
296
  enterKeyHint: 'go',
@@ -295,7 +307,7 @@ function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
295
307
  inputProps: inputProps,
296
308
  collectionProps: (0, $4yz2I$reactariautils.mergeProps)(collectionProps, {
297
309
  shouldUseVirtualFocus: shouldUseVirtualFocus,
298
- disallowTypeAhead: true
310
+ disallowTypeAhead: shouldUseVirtualFocus
299
311
  }),
300
312
  collectionRef: mergedCollectionRef,
301
313
  filter: filter != null ? filterFn : undefined
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAuEM,SAAS,0CAAmB,KAAiC,EAAE,KAAwB;IAC5F,IAAI,YACF,QAAQ,iBACR,aAAa,UACb,MAAM,yBACN,wBAAwB,4BACxB,sBAAsB,OACvB,GAAG;IAEJ,IAAI,eAAe,CAAA,GAAA,+BAAQ;IAC3B,IAAI,UAAU,CAAA,GAAA,mBAAK,EAA6C;IAChE,IAAI,4BAA4B,CAAA,GAAA,mBAAK,EAAE;IACvC,IAAI,yBAAyB,CAAA,GAAA,mB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OAAO;gBACjD,CAAA,GAAA,0CAAmB,EAAE,cAAc,OAAO,EAAG;YAC/C;QACF;IACF;IAEA,uGAAuG;IACvG,uDAAuD;IACvD,IAAI,aAAa;QACf,OAAO,MAAM,UAAU;kBACvB;IACF;QAI2B;IAF3B,IAAI,oBAAoB;mBACtB;QACA,yBAAyB,CAAA,uBAAA,MAAM,aAAa,cAAnB,kCAAA,uBAAuB;gBAChD;iBACA;IACF;IAEA,IAAI,cACF,aAAa;QACX,GAAG,UAAU;QACb,GAAI,yBAAyB,iBAAiB;QAC9C,cAAc;QACd,iBAAiB;QACjB,mFAAmF;QACnF,qBAAqB;QACrB,qGAAqG;QACrG,aAAa;QACb,gEAAgE;QAChE,YAAY;QACZ,cAAc;IAChB;IAGF,OAAO;oBACL;QACA,iBAAiB,CAAA,GAAA,gCAAS,EAAE,iBAAiB;mCAC3C;YACA,mBAAmB;QACrB;QACA,eAAe;QACf,QAAQ,UAAU,OAAO,WAAW;IACtC;AACF","sources":["packages/@react-aria/autocomplete/src/useAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';\nimport {AriaTextFieldProps} from '@react-aria/textfield';\nimport {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';\nimport {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';\nimport {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface CollectionOptions extends DOMProps, AriaLabelingProps {\n /** Whether the collection items should use virtual focus instead of being focused directly. */\n shouldUseVirtualFocus: boolean,\n /** Whether typeahead is disabled. */\n disallowTypeAhead: boolean\n}\n\nexport interface InputProps<T = FocusableElement> extends DOMProps,\n FocusEvents<T>,\n KeyboardEvents,\n Pick<ValueBase<string>, 'onChange' | 'value'>,\n Pick<AriaTextFieldProps, 'enterKeyHint' | 'aria-controls' | 'aria-autocomplete' | 'aria-activedescendant' | 'spellCheck' | 'autoCorrect' | 'autoComplete'> {}\n\nexport interface AriaAutocompleteProps<T> extends AutocompleteProps {\n /**\n * An optional filter function used to determine if a option should be included in the autocomplete list.\n * Include this if the items you are providing to your wrapped collection aren't filtered by default.\n */\n filter?: (textValue: string, inputValue: string, node: Node<T>) => boolean,\n\n /**\n * Whether or not to focus the first item in the collection after a filter is performed. Note this is only applicable\n * if virtual focus behavior is not turned off via `disableVirtualFocus`.\n * @default false\n */\n disableAutoFocusFirst?: boolean,\n\n /**\n * Whether the autocomplete should disable virtual focus, instead making the wrapped collection directly tabbable.\n * @default false\n */\n disableVirtualFocus?: boolean\n}\n\nexport interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T>, 'children'> {\n /** The ref for the wrapped collection element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the wrapped collection element. */\n collectionRef: RefObject<HTMLElement | null>\n}\n\nexport interface AutocompleteAria<T> {\n /** Props for the autocomplete input element. These should be passed to the input's aria hooks (e.g. useTextField/useSearchField/etc) respectively. */\n inputProps: InputProps,\n /** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */\n collectionProps: CollectionOptions,\n /** Ref to attach to the wrapped collection. */\n collectionRef: RefObject<HTMLElement | null>,\n /** A filter function that returns if the provided collection node should be filtered out of the collection. */\n filter?: (nodeTextValue: string, node: Node<T>) => boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an autocomplete component.\n * An autocomplete combines a text input with a collection, allowing users to filter the collection's contents match a query.\n * @param props - Props for the autocomplete.\n * @param state - State for the autocomplete, as returned by `useAutocompleteState`.\n */\nexport function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: AutocompleteState): AutocompleteAria<T> {\n let {\n inputRef,\n collectionRef,\n filter,\n disableAutoFocusFirst = false,\n disableVirtualFocus = false\n } = props;\n\n let collectionId = useSlotId();\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let delayNextActiveDescendant = useRef(false);\n let queuedActiveDescendant = useRef<string | null>(null);\n let lastCollectionNode = useRef<HTMLElement>(null);\n\n // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually\n // moving focus back to the subtriggers\n let isMobileScreenReader = getInteractionModality() === 'virtual' && (isIOS() || isAndroid());\n let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;\n useEffect(() => {\n return () => clearTimeout(timeout.current);\n }, []);\n\n let updateActiveDescendant = useEffectEvent((e: Event) => {\n // Ensure input is focused if the user clicks on the collection directly.\n if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {\n inputRef.current.focus();\n }\n\n let target = e.target as Element | null;\n if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {\n return;\n }\n\n clearTimeout(timeout.current);\n if (target !== collectionRef.current) {\n if (delayNextActiveDescendant.current) {\n queuedActiveDescendant.current = target.id;\n timeout.current = setTimeout(() => {\n state.setFocusedNodeId(target.id);\n }, 500);\n } else {\n queuedActiveDescendant.current = target.id;\n state.setFocusedNodeId(target.id);\n }\n } else if (queuedActiveDescendant.current && !document.getElementById(queuedActiveDescendant.current)) {\n // If we recieve a focus event refocusing the collection, either we have newly refocused the input and are waiting for the\n // wrapped collection to refocus the previously focused node if any OR\n // we are in a state where we've filtered to such a point that there aren't any matching items in the collection to focus.\n // In this case we want to clear tracked item if any and clear active descendant\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n }\n\n delayNextActiveDescendant.current = false;\n });\n\n let callbackRef = useCallback((collectionNode) => {\n if (collectionNode != null) {\n // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement\n // of the letter you just typed. If we recieve another focus event then we clear the queued update\n // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles\n // React 19's extra call of the callback ref in strict mode\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n lastCollectionNode.current = collectionNode;\n collectionNode.addEventListener('focusin', updateActiveDescendant);\n } else {\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n }\n }, [updateActiveDescendant]);\n\n // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection\n let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));\n\n let focusFirstItem = useEffectEvent(() => {\n delayNextActiveDescendant.current = true;\n collectionRef.current?.dispatchEvent(\n new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n focusStrategy: 'first'\n }\n })\n );\n });\n\n let clearVirtualFocus = useEffectEvent((clearFocusKey?: boolean) => {\n moveVirtualFocus(getActiveElement());\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n let clearFocusEvent = new CustomEvent(CLEAR_FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n clearFocusKey\n }\n });\n clearTimeout(timeout.current);\n delayNextActiveDescendant.current = false;\n collectionRef.current?.dispatchEvent(clearFocusEvent);\n });\n\n let lastInputType = useRef('');\n useEvent(inputRef, 'input', e => {\n let {inputType} = e as InputEvent;\n lastInputType.current = inputType;\n });\n\n let onChange = (value: string) => {\n // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when modifying the text via\n // copy paste/backspacing/undo/redo for screen reader announcements\n if (lastInputType.current === 'insertText' && !disableAutoFocusFirst) {\n focusFirstItem();\n } else if (lastInputType.current && (lastInputType.current.includes('insert') || lastInputType.current.includes('delete') || lastInputType.current.includes('history'))) {\n clearVirtualFocus(true);\n\n // If onChange was triggered before the timeout actually updated the activedescendant, we need to fire\n // our own dispatchVirtualFocus so focusVisible gets reapplied on the input\n if (getVirtuallyFocusedElement(document) === inputRef.current) {\n dispatchVirtualFocus(inputRef.current!, null);\n }\n }\n\n state.setInputValue(value);\n };\n\n let keyDownTarget = useRef<Element | null>(null);\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {\n keyDownTarget.current = e.target as Element;\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n let focusedNodeId = queuedActiveDescendant.current;\n switch (e.key) {\n case 'a':\n if (isCtrlKeyPressed(e)) {\n return;\n }\n break;\n case 'Escape':\n // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and\n // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check\n // for isPropagationStopped\n if (e.isDefaultPrevented()) {\n return;\n }\n break;\n case ' ':\n // Space shouldn't trigger onAction so early return.\n return;\n case 'Tab':\n // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)\n // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n return;\n case 'Home':\n case 'End':\n case 'PageDown':\n case 'PageUp':\n case 'ArrowUp':\n case 'ArrowDown': {\n if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) {\n return;\n }\n\n // Prevent these keys from moving the text cursor in the input\n e.preventDefault();\n // Move virtual focus into the wrapped collection\n let focusCollection = new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true\n });\n\n collectionRef.current?.dispatchEvent(focusCollection);\n break;\n }\n }\n\n // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter\n // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events\n // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble\n // as expected\n if (!e.isPropagationStopped()) {\n e.stopPropagation();\n }\n\n let shouldPerformDefaultAction = true;\n if (collectionRef.current !== null) {\n if (focusedNodeId == null) {\n shouldPerformDefaultAction = collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n } else {\n let item = document.getElementById(focusedNodeId);\n if (item) {\n shouldPerformDefaultAction = item?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n }\n }\n }\n\n if (shouldPerformDefaultAction) {\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowRight': {\n // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the\n // user's keyboard navigation restarts from where they left off\n clearVirtualFocus();\n break;\n }\n case 'Enter':\n // Trigger click action on item when Enter key was pressed.\n if (focusedNodeId != null) {\n let item = document.getElementById(focusedNodeId);\n item?.click();\n }\n break;\n }\n } else {\n // TODO: check if we can do this, want to stop textArea from using its default Enter behavior so items are properly triggered\n e.preventDefault();\n }\n };\n\n let onKeyUpCapture = useEffectEvent((e) => {\n // Dispatch simulated key up events for things like triggering links in listbox\n // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair\n // is detected by usePress instead of the original keyup originating from the input\n if (e.target === keyDownTarget.current) {\n e.stopImmediatePropagation();\n let focusedNodeId = queuedActiveDescendant.current;\n if (focusedNodeId == null) {\n collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n } else {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n }\n });\n\n useEffect(() => {\n document.addEventListener('keyup', onKeyUpCapture, true);\n return () => {\n document.removeEventListener('keyup', onKeyUpCapture, true);\n };\n }, [onKeyUpCapture]);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');\n let collectionProps = useLabels({\n id: collectionId,\n 'aria-label': stringFormatter.format('collectionLabel')\n });\n\n let filterFn = useCallback((nodeTextValue: string, node: Node<T>) => {\n if (filter) {\n return filter(nodeTextValue, state.inputValue, node);\n }\n\n return true;\n }, [state.inputValue, filter]);\n\n // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the\n // focus ring on the virtually focused collection when are actually interacting with the Autocomplete\n let onBlur = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (lastFocusedNode) {\n dispatchVirtualBlur(lastFocusedNode, e.relatedTarget);\n }\n };\n\n let onFocus = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (curFocusedNode) {\n let target = e.target;\n queueMicrotask(() => {\n // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item\n dispatchVirtualBlur(target, collectionRef.current);\n dispatchVirtualFocus(collectionRef.current!, target);\n });\n }\n };\n\n // Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually\n // being filtered/allows filtering by the Autocomplete.\n let inputProps = {\n value: state.inputValue,\n onChange\n } as AriaTextFieldProps<FocusableElement>;\n\n let virtualFocusProps = {\n onKeyDown,\n 'aria-activedescendant': state.focusedNodeId ?? undefined,\n onBlur,\n onFocus\n };\n\n if (collectionId) {\n inputProps = {\n ...inputProps,\n ...(shouldUseVirtualFocus && virtualFocusProps),\n enterKeyHint: 'go',\n 'aria-controls': collectionId,\n // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n 'aria-autocomplete': 'list',\n // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.\n autoCorrect: 'off',\n // This disable's the macOS Safari spell check auto corrections.\n spellCheck: 'false',\n autoComplete: 'off'\n };\n }\n\n return {\n inputProps,\n collectionProps: mergeProps(collectionProps, {\n shouldUseVirtualFocus,\n disallowTypeAhead: true\n }),\n collectionRef: mergedCollectionRef,\n filter: filter != null ? filterFn : undefined\n };\n}\n"],"names":[],"version":3,"file":"useAutocomplete.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAuEM,SAAS,0CAAmB,KAAiC,EAAE,KAAwB;IAC5F,IAAI,YACF,QAAQ,iBACR,aAAa,UACb,MAAM,yBACN,wBAAwB,4BACxB,sBAAsB,OACvB,GAAG;IAEJ,IAAI,eAAe,CAAA,GAAA,2BAAI;IACvB,IAAI,UAAU,CAAA,GAAA,mBAAK,EAA6C;IAChE,IAAI,4BAA4B,CAAA,GAAA,mBAAK,EAAE;IACvC,IAAI,yBAAyB,CAAA,GAAA,mBAAK,EAAiB;IAEnD,2HAA2H;IAC3H,uCAAuC;IACvC,IAAI,uBAAuB,CAAA,GAAA,mDAAqB,QAAQ,aAAc,CAAA,CAAA,GAAA,2BAAI,OAAO,CAAA,GAAA,+BAAQ,GAAE;IAC3F,IAAI,CAAC,uBAAuB,yBAAyB,GAAG,CAAA,GAAA,qBAAO,EAAE,CAAC,wBAAwB,CAAC;IAC3F,6IAA6I;IAC7I,iEAAiE;IACjE,IAAI,CAAC,eAAe,iBAAiB,GAAG,CAAA,GAAA,qBAAO,EAAE;IAEjD,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO,IAAM,aAAa,QAAQ,OAAO;IAC3C,GAAG,EAAE;IAEL,IAAI,8BAA8B,CAAA,GAAA,oCAAa,EA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MAAM,UAAU;kBACvB;IACF;QAI2B;IAF3B,IAAI,oBAAoB;mBACtB;QACA,yBAAyB,CAAA,uBAAA,MAAM,aAAa,cAAnB,kCAAA,uBAAuB;gBAChD;iBACA;IACF;IAEA,IAAI,eACF,aAAa;QACX,GAAG,UAAU;QACb,GAAI,yBAAyB,iBAAiB;QAC9C,cAAc;QACd,iBAAiB;QACjB,mFAAmF;QACnF,qBAAqB;QACrB,qGAAqG;QACrG,aAAa;QACb,gEAAgE;QAChE,YAAY;QACZ,cAAc;IAChB;IAGF,OAAO;oBACL;QACA,iBAAiB,CAAA,GAAA,gCAAS,EAAE,iBAAiB;mCAC3C;YACA,mBAAmB;QACrB;QACA,eAAe;QACf,QAAQ,UAAU,OAAO,WAAW;IACtC;AACF","sources":["packages/@react-aria/autocomplete/src/useAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';\nimport {AriaTextFieldProps} from '@react-aria/textfield';\nimport {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';\nimport {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useId, useLabels, useLayoutEffect, useObjectRef} from '@react-aria/utils';\nimport {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';\nimport {getInteractionModality, getPointerType} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface CollectionOptions extends DOMProps, AriaLabelingProps {\n /** Whether the collection items should use virtual focus instead of being focused directly. */\n shouldUseVirtualFocus: boolean,\n /** Whether typeahead is disabled. */\n disallowTypeAhead: boolean\n}\n\nexport interface InputProps<T = FocusableElement> extends DOMProps,\n FocusEvents<T>,\n KeyboardEvents,\n Pick<ValueBase<string>, 'onChange' | 'value'>,\n Pick<AriaTextFieldProps, 'enterKeyHint' | 'aria-controls' | 'aria-autocomplete' | 'aria-activedescendant' | 'spellCheck' | 'autoCorrect' | 'autoComplete'> {}\n\nexport interface AriaAutocompleteProps<T> extends AutocompleteProps {\n /**\n * An optional filter function used to determine if a option should be included in the autocomplete list.\n * Include this if the items you are providing to your wrapped collection aren't filtered by default.\n */\n filter?: (textValue: string, inputValue: string, node: Node<T>) => boolean,\n\n /**\n * Whether or not to focus the first item in the collection after a filter is performed. Note this is only applicable\n * if virtual focus behavior is not turned off via `disableVirtualFocus`.\n * @default false\n */\n disableAutoFocusFirst?: boolean,\n\n /**\n * Whether the autocomplete should disable virtual focus, instead making the wrapped collection directly tabbable.\n * @default false\n */\n disableVirtualFocus?: boolean\n}\n\nexport interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T>, 'children'> {\n /** The ref for the wrapped collection element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the wrapped collection element. */\n collectionRef: RefObject<HTMLElement | null>\n}\n\nexport interface AutocompleteAria<T> {\n /** Props for the autocomplete input element. These should be passed to the input's aria hooks (e.g. useTextField/useSearchField/etc) respectively. */\n inputProps: InputProps,\n /** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */\n collectionProps: CollectionOptions,\n /** Ref to attach to the wrapped collection. */\n collectionRef: RefObject<HTMLElement | null>,\n /** A filter function that returns if the provided collection node should be filtered out of the collection. */\n filter?: (nodeTextValue: string, node: Node<T>) => boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an autocomplete component.\n * An autocomplete combines a text input with a collection, allowing users to filter the collection's contents match a query.\n * @param props - Props for the autocomplete.\n * @param state - State for the autocomplete, as returned by `useAutocompleteState`.\n */\nexport function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: AutocompleteState): AutocompleteAria<T> {\n let {\n inputRef,\n collectionRef,\n filter,\n disableAutoFocusFirst = false,\n disableVirtualFocus = false\n } = props;\n\n let collectionId = useId();\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let delayNextActiveDescendant = useRef(false);\n let queuedActiveDescendant = useRef<string | null>(null);\n\n // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually\n // moving focus back to the subtriggers\n let isMobileScreenReader = getInteractionModality() === 'virtual' && (isIOS() || isAndroid());\n let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = useState(!isMobileScreenReader && !disableVirtualFocus);\n // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input\n // since it isn't attached to a filterable collection (e.g. Tabs)\n let [hasCollection, setHasCollection] = useState(false);\n\n useEffect(() => {\n return () => clearTimeout(timeout.current);\n }, []);\n\n let updateActiveDescendantEvent = useEffectEvent((e: Event) => {\n // Ensure input is focused if the user clicks on the collection directly.\n // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options\n if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current && getPointerType() !== 'touch') {\n inputRef.current.focus();\n }\n\n let target = e.target as Element | null;\n if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {\n return;\n }\n\n clearTimeout(timeout.current);\n if (target !== collectionRef.current) {\n if (delayNextActiveDescendant.current) {\n queuedActiveDescendant.current = target.id;\n timeout.current = setTimeout(() => {\n state.setFocusedNodeId(target.id);\n }, 500);\n } else {\n queuedActiveDescendant.current = target.id;\n state.setFocusedNodeId(target.id);\n }\n } else if (queuedActiveDescendant.current && !document.getElementById(queuedActiveDescendant.current)) {\n // If we recieve a focus event refocusing the collection, either we have newly refocused the input and are waiting for the\n // wrapped collection to refocus the previously focused node if any OR\n // we are in a state where we've filtered to such a point that there aren't any matching items in the collection to focus.\n // In this case we want to clear tracked item if any and clear active descendant\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n }\n\n delayNextActiveDescendant.current = false;\n });\n\n let [collectionNode, setCollectionNode] = useState<HTMLElement | null>(null);\n let callbackRef = useCallback((node) => {\n setCollectionNode(node);\n if (node != null) {\n // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it\n // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless\n // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.\n if (node.getAttribute('tabindex') != null) {\n setShouldUseVirtualFocus(false);\n }\n setHasCollection(true);\n } else {\n setHasCollection(false);\n }\n }, []);\n useLayoutEffect(() => {\n if (collectionNode != null) {\n // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement\n // of the letter you just typed. If we recieve another focus event then we clear the queued update\n collectionNode.addEventListener('focusin', updateActiveDescendantEvent);\n }\n return () => {\n collectionNode?.removeEventListener('focusin', updateActiveDescendantEvent);\n };\n }, [collectionNode]);\n\n // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection\n let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));\n\n let focusFirstItem = useCallback(() => {\n delayNextActiveDescendant.current = true;\n collectionRef.current?.dispatchEvent(\n new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n focusStrategy: 'first'\n }\n })\n );\n }, [collectionRef]);\n\n let clearVirtualFocus = useCallback((clearFocusKey?: boolean) => {\n moveVirtualFocus(getActiveElement());\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n let clearFocusEvent = new CustomEvent(CLEAR_FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n clearFocusKey\n }\n });\n clearTimeout(timeout.current);\n delayNextActiveDescendant.current = false;\n collectionRef.current?.dispatchEvent(clearFocusEvent);\n }, [collectionRef, state]);\n\n let lastInputType = useRef('');\n useEvent(inputRef, 'input', e => {\n let {inputType} = e as InputEvent;\n lastInputType.current = inputType;\n });\n\n let onChange = (value: string) => {\n // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when modifying the text via\n // copy paste/backspacing/undo/redo for screen reader announcements\n if (lastInputType.current === 'insertText' && !disableAutoFocusFirst) {\n focusFirstItem();\n } else if (lastInputType.current && (lastInputType.current.includes('insert') || lastInputType.current.includes('delete') || lastInputType.current.includes('history'))) {\n clearVirtualFocus(true);\n\n // If onChange was triggered before the timeout actually updated the activedescendant, we need to fire\n // our own dispatchVirtualFocus so focusVisible gets reapplied on the input\n if (getVirtuallyFocusedElement(document) === inputRef.current) {\n dispatchVirtualFocus(inputRef.current!, null);\n }\n }\n\n state.setInputValue(value);\n };\n\n let keyDownTarget = useRef<Element | null>(null);\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {\n keyDownTarget.current = e.target as Element;\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n let focusedNodeId = queuedActiveDescendant.current;\n switch (e.key) {\n case 'a':\n if (isCtrlKeyPressed(e)) {\n return;\n }\n break;\n case 'Escape':\n // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and\n // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check\n // for isPropagationStopped\n if (e.isDefaultPrevented()) {\n return;\n }\n break;\n case ' ':\n // Space shouldn't trigger onAction so early return.\n return;\n case 'Tab':\n // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)\n // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n return;\n case 'Home':\n case 'End':\n case 'PageDown':\n case 'PageUp':\n case 'ArrowUp':\n case 'ArrowDown': {\n if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) {\n return;\n }\n\n // Prevent these keys from moving the text cursor in the input\n e.preventDefault();\n // Move virtual focus into the wrapped collection\n let focusCollection = new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true\n });\n\n collectionRef.current?.dispatchEvent(focusCollection);\n break;\n }\n }\n\n // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter\n // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events\n // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble\n // as expected\n if (!e.isPropagationStopped()) {\n e.stopPropagation();\n }\n\n let shouldPerformDefaultAction = true;\n if (collectionRef.current !== null) {\n if (focusedNodeId == null) {\n shouldPerformDefaultAction = collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n } else {\n let item = document.getElementById(focusedNodeId);\n if (item) {\n shouldPerformDefaultAction = item?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n }\n }\n }\n\n if (shouldPerformDefaultAction) {\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowRight': {\n // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the\n // user's keyboard navigation restarts from where they left off\n clearVirtualFocus();\n break;\n }\n case 'Enter':\n // Trigger click action on item when Enter key was pressed.\n if (focusedNodeId != null) {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(new PointerEvent('click', e.nativeEvent));\n }\n break;\n }\n } else {\n // TODO: check if we can do this, want to stop textArea from using its default Enter behavior so items are properly triggered\n e.preventDefault();\n }\n };\n\n let onKeyUpCapture = useEffectEvent((e) => {\n // Dispatch simulated key up events for things like triggering links in listbox\n // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair\n // is detected by usePress instead of the original keyup originating from the input\n if (e.target === keyDownTarget.current) {\n e.stopImmediatePropagation();\n let focusedNodeId = queuedActiveDescendant.current;\n if (focusedNodeId == null) {\n collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n } else {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n }\n });\n\n useEffect(() => {\n document.addEventListener('keyup', onKeyUpCapture, true);\n return () => {\n document.removeEventListener('keyup', onKeyUpCapture, true);\n };\n }, []);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');\n let collectionProps = useLabels({\n id: collectionId,\n 'aria-label': stringFormatter.format('collectionLabel')\n });\n\n let filterFn = useCallback((nodeTextValue: string, node: Node<T>) => {\n if (filter) {\n return filter(nodeTextValue, state.inputValue, node);\n }\n\n return true;\n }, [state.inputValue, filter]);\n\n // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the\n // focus ring on the virtually focused collection when are actually interacting with the Autocomplete\n let onBlur = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (lastFocusedNode) {\n dispatchVirtualBlur(lastFocusedNode, e.relatedTarget);\n }\n };\n\n let onFocus = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (curFocusedNode) {\n let target = e.target;\n queueMicrotask(() => {\n // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item\n dispatchVirtualBlur(target, collectionRef.current);\n dispatchVirtualFocus(collectionRef.current!, target);\n });\n }\n };\n\n // Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually\n // being filtered/allows filtering by the Autocomplete.\n let inputProps = {\n value: state.inputValue,\n onChange\n } as AriaTextFieldProps<FocusableElement>;\n\n let virtualFocusProps = {\n onKeyDown,\n 'aria-activedescendant': state.focusedNodeId ?? undefined,\n onBlur,\n onFocus\n };\n\n if (hasCollection) {\n inputProps = {\n ...inputProps,\n ...(shouldUseVirtualFocus && virtualFocusProps),\n enterKeyHint: 'go',\n 'aria-controls': collectionId,\n // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n 'aria-autocomplete': 'list',\n // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.\n autoCorrect: 'off',\n // This disable's the macOS Safari spell check auto corrections.\n spellCheck: 'false',\n autoComplete: 'off'\n };\n }\n\n return {\n inputProps,\n collectionProps: mergeProps(collectionProps, {\n shouldUseVirtualFocus,\n disallowTypeAhead: shouldUseVirtualFocus\n }),\n collectionRef: mergedCollectionRef,\n filter: filter != null ? filterFn : undefined\n };\n}\n"],"names":[],"version":3,"file":"useAutocomplete.main.js.map"}
@@ -1,8 +1,8 @@
1
1
  import $4ELxY$intlStringsmodulejs from "./intlStrings.mjs";
2
- import {useSlotId as $4ELxY$useSlotId, isIOS as $4ELxY$isIOS, isAndroid as $4ELxY$isAndroid, useEffectEvent as $4ELxY$useEffectEvent, getActiveElement as $4ELxY$getActiveElement, getOwnerDocument as $4ELxY$getOwnerDocument, useObjectRef as $4ELxY$useObjectRef, mergeRefs as $4ELxY$mergeRefs, FOCUS_EVENT as $4ELxY$FOCUS_EVENT, CLEAR_FOCUS_EVENT as $4ELxY$CLEAR_FOCUS_EVENT, useEvent as $4ELxY$useEvent, isCtrlKeyPressed as $4ELxY$isCtrlKeyPressed, useLabels as $4ELxY$useLabels, mergeProps as $4ELxY$mergeProps} from "@react-aria/utils";
2
+ import {useId as $4ELxY$useId, isIOS as $4ELxY$isIOS, isAndroid as $4ELxY$isAndroid, useEffectEvent as $4ELxY$useEffectEvent, getActiveElement as $4ELxY$getActiveElement, getOwnerDocument as $4ELxY$getOwnerDocument, useLayoutEffect as $4ELxY$useLayoutEffect, useObjectRef as $4ELxY$useObjectRef, mergeRefs as $4ELxY$mergeRefs, FOCUS_EVENT as $4ELxY$FOCUS_EVENT, CLEAR_FOCUS_EVENT as $4ELxY$CLEAR_FOCUS_EVENT, useEvent as $4ELxY$useEvent, isCtrlKeyPressed as $4ELxY$isCtrlKeyPressed, useLabels as $4ELxY$useLabels, mergeProps as $4ELxY$mergeProps} from "@react-aria/utils";
3
3
  import {moveVirtualFocus as $4ELxY$moveVirtualFocus, getVirtuallyFocusedElement as $4ELxY$getVirtuallyFocusedElement, dispatchVirtualFocus as $4ELxY$dispatchVirtualFocus, dispatchVirtualBlur as $4ELxY$dispatchVirtualBlur} from "@react-aria/focus";
4
- import {getInteractionModality as $4ELxY$getInteractionModality} from "@react-aria/interactions";
5
- import {useRef as $4ELxY$useRef, useEffect as $4ELxY$useEffect, useCallback as $4ELxY$useCallback, useMemo as $4ELxY$useMemo} from "react";
4
+ import {getInteractionModality as $4ELxY$getInteractionModality, getPointerType as $4ELxY$getPointerType} from "@react-aria/interactions";
5
+ import {useRef as $4ELxY$useRef, useState as $4ELxY$useState, useEffect as $4ELxY$useEffect, useCallback as $4ELxY$useCallback, useMemo as $4ELxY$useMemo} from "react";
6
6
  import {useLocalizedStringFormatter as $4ELxY$useLocalizedStringFormatter} from "@react-aria/i18n";
7
7
 
8
8
 
@@ -27,21 +27,24 @@ function $parcel$interopDefault(a) {
27
27
 
28
28
  function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
29
29
  let { inputRef: inputRef, collectionRef: collectionRef, filter: filter, disableAutoFocusFirst: disableAutoFocusFirst = false, disableVirtualFocus: disableVirtualFocus = false } = props;
30
- let collectionId = (0, $4ELxY$useSlotId)();
30
+ let collectionId = (0, $4ELxY$useId)();
31
31
  let timeout = (0, $4ELxY$useRef)(undefined);
32
32
  let delayNextActiveDescendant = (0, $4ELxY$useRef)(false);
33
33
  let queuedActiveDescendant = (0, $4ELxY$useRef)(null);
34
- let lastCollectionNode = (0, $4ELxY$useRef)(null);
35
34
  // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
36
35
  // moving focus back to the subtriggers
37
36
  let isMobileScreenReader = (0, $4ELxY$getInteractionModality)() === 'virtual' && ((0, $4ELxY$isIOS)() || (0, $4ELxY$isAndroid)());
38
- let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;
37
+ let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = (0, $4ELxY$useState)(!isMobileScreenReader && !disableVirtualFocus);
38
+ // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input
39
+ // since it isn't attached to a filterable collection (e.g. Tabs)
40
+ let [hasCollection, setHasCollection] = (0, $4ELxY$useState)(false);
39
41
  (0, $4ELxY$useEffect)(()=>{
40
42
  return ()=>clearTimeout(timeout.current);
41
43
  }, []);
42
- let updateActiveDescendant = (0, $4ELxY$useEffectEvent)((e)=>{
44
+ let updateActiveDescendantEvent = (0, $4ELxY$useEffectEvent)((e)=>{
43
45
  // Ensure input is focused if the user clicks on the collection directly.
44
- if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4ELxY$getActiveElement)((0, $4ELxY$getOwnerDocument)(inputRef.current)) !== inputRef.current) inputRef.current.focus();
46
+ // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options
47
+ if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4ELxY$getActiveElement)((0, $4ELxY$getOwnerDocument)(inputRef.current)) !== inputRef.current && (0, $4ELxY$getPointerType)() !== 'touch') inputRef.current.focus();
45
48
  let target = e.target;
46
49
  if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) return;
47
50
  clearTimeout(timeout.current);
@@ -65,27 +68,33 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
65
68
  }
66
69
  delayNextActiveDescendant.current = false;
67
70
  });
68
- let callbackRef = (0, $4ELxY$useCallback)((collectionNode)=>{
69
- var _lastCollectionNode_current;
70
- if (collectionNode != null) {
71
- var // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
72
- // of the letter you just typed. If we recieve another focus event then we clear the queued update
73
- // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
74
- // React 19's extra call of the callback ref in strict mode
75
- _lastCollectionNode_current1;
76
- (_lastCollectionNode_current1 = lastCollectionNode.current) === null || _lastCollectionNode_current1 === void 0 ? void 0 : _lastCollectionNode_current1.removeEventListener('focusin', updateActiveDescendant);
77
- lastCollectionNode.current = collectionNode;
78
- collectionNode.addEventListener('focusin', updateActiveDescendant);
79
- } else (_lastCollectionNode_current = lastCollectionNode.current) === null || _lastCollectionNode_current === void 0 ? void 0 : _lastCollectionNode_current.removeEventListener('focusin', updateActiveDescendant);
71
+ let [collectionNode, setCollectionNode] = (0, $4ELxY$useState)(null);
72
+ let callbackRef = (0, $4ELxY$useCallback)((node)=>{
73
+ setCollectionNode(node);
74
+ if (node != null) {
75
+ // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it
76
+ // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless
77
+ // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.
78
+ if (node.getAttribute('tabindex') != null) setShouldUseVirtualFocus(false);
79
+ setHasCollection(true);
80
+ } else setHasCollection(false);
81
+ }, []);
82
+ (0, $4ELxY$useLayoutEffect)(()=>{
83
+ if (collectionNode != null) // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
84
+ // of the letter you just typed. If we recieve another focus event then we clear the queued update
85
+ collectionNode.addEventListener('focusin', updateActiveDescendantEvent);
86
+ return ()=>{
87
+ collectionNode === null || collectionNode === void 0 ? void 0 : collectionNode.removeEventListener('focusin', updateActiveDescendantEvent);
88
+ };
80
89
  }, [
81
- updateActiveDescendant
90
+ collectionNode
82
91
  ]);
83
92
  // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
84
93
  let mergedCollectionRef = (0, $4ELxY$useObjectRef)((0, $4ELxY$useMemo)(()=>(0, $4ELxY$mergeRefs)(collectionRef, callbackRef), [
85
94
  collectionRef,
86
95
  callbackRef
87
96
  ]));
88
- let focusFirstItem = (0, $4ELxY$useEffectEvent)(()=>{
97
+ let focusFirstItem = (0, $4ELxY$useCallback)(()=>{
89
98
  var _collectionRef_current;
90
99
  delayNextActiveDescendant.current = true;
91
100
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new CustomEvent((0, $4ELxY$FOCUS_EVENT), {
@@ -95,8 +104,10 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
95
104
  focusStrategy: 'first'
96
105
  }
97
106
  }));
98
- });
99
- let clearVirtualFocus = (0, $4ELxY$useEffectEvent)((clearFocusKey)=>{
107
+ }, [
108
+ collectionRef
109
+ ]);
110
+ let clearVirtualFocus = (0, $4ELxY$useCallback)((clearFocusKey)=>{
100
111
  var _collectionRef_current;
101
112
  (0, $4ELxY$moveVirtualFocus)((0, $4ELxY$getActiveElement)());
102
113
  queuedActiveDescendant.current = null;
@@ -111,7 +122,10 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
111
122
  clearTimeout(timeout.current);
112
123
  delayNextActiveDescendant.current = false;
113
124
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(clearFocusEvent);
114
- });
125
+ }, [
126
+ collectionRef,
127
+ state
128
+ ]);
115
129
  let lastInputType = (0, $4ELxY$useRef)('');
116
130
  (0, $4ELxY$useEvent)(inputRef, 'input', (e)=>{
117
131
  let { inputType: inputType } = e;
@@ -198,7 +212,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
198
212
  // Trigger click action on item when Enter key was pressed.
199
213
  if (focusedNodeId != null) {
200
214
  let item = document.getElementById(focusedNodeId);
201
- item === null || item === void 0 ? void 0 : item.click();
215
+ item === null || item === void 0 ? void 0 : item.dispatchEvent(new PointerEvent('click', e.nativeEvent));
202
216
  }
203
217
  break;
204
218
  }
@@ -225,9 +239,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
225
239
  return ()=>{
226
240
  document.removeEventListener('keyup', onKeyUpCapture, true);
227
241
  };
228
- }, [
229
- onKeyUpCapture
230
- ]);
242
+ }, []);
231
243
  let stringFormatter = (0, $4ELxY$useLocalizedStringFormatter)((0, ($parcel$interopDefault($4ELxY$intlStringsmodulejs))), '@react-aria/autocomplete');
232
244
  let collectionProps = (0, $4ELxY$useLabels)({
233
245
  id: collectionId,
@@ -272,7 +284,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
272
284
  onBlur: onBlur,
273
285
  onFocus: onFocus
274
286
  };
275
- if (collectionId) inputProps = {
287
+ if (hasCollection) inputProps = {
276
288
  ...inputProps,
277
289
  ...shouldUseVirtualFocus && virtualFocusProps,
278
290
  enterKeyHint: 'go',
@@ -289,7 +301,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
289
301
  inputProps: inputProps,
290
302
  collectionProps: (0, $4ELxY$mergeProps)(collectionProps, {
291
303
  shouldUseVirtualFocus: shouldUseVirtualFocus,
292
- disallowTypeAhead: true
304
+ disallowTypeAhead: shouldUseVirtualFocus
293
305
  }),
294
306
  collectionRef: mergedCollectionRef,
295
307
  filter: filter != null ? filterFn : undefined
@@ -1,8 +1,8 @@
1
1
  import $4ELxY$intlStringsmodulejs from "./intlStrings.module.js";
2
- import {useSlotId as $4ELxY$useSlotId, isIOS as $4ELxY$isIOS, isAndroid as $4ELxY$isAndroid, useEffectEvent as $4ELxY$useEffectEvent, getActiveElement as $4ELxY$getActiveElement, getOwnerDocument as $4ELxY$getOwnerDocument, useObjectRef as $4ELxY$useObjectRef, mergeRefs as $4ELxY$mergeRefs, FOCUS_EVENT as $4ELxY$FOCUS_EVENT, CLEAR_FOCUS_EVENT as $4ELxY$CLEAR_FOCUS_EVENT, useEvent as $4ELxY$useEvent, isCtrlKeyPressed as $4ELxY$isCtrlKeyPressed, useLabels as $4ELxY$useLabels, mergeProps as $4ELxY$mergeProps} from "@react-aria/utils";
2
+ import {useId as $4ELxY$useId, isIOS as $4ELxY$isIOS, isAndroid as $4ELxY$isAndroid, useEffectEvent as $4ELxY$useEffectEvent, getActiveElement as $4ELxY$getActiveElement, getOwnerDocument as $4ELxY$getOwnerDocument, useLayoutEffect as $4ELxY$useLayoutEffect, useObjectRef as $4ELxY$useObjectRef, mergeRefs as $4ELxY$mergeRefs, FOCUS_EVENT as $4ELxY$FOCUS_EVENT, CLEAR_FOCUS_EVENT as $4ELxY$CLEAR_FOCUS_EVENT, useEvent as $4ELxY$useEvent, isCtrlKeyPressed as $4ELxY$isCtrlKeyPressed, useLabels as $4ELxY$useLabels, mergeProps as $4ELxY$mergeProps} from "@react-aria/utils";
3
3
  import {moveVirtualFocus as $4ELxY$moveVirtualFocus, getVirtuallyFocusedElement as $4ELxY$getVirtuallyFocusedElement, dispatchVirtualFocus as $4ELxY$dispatchVirtualFocus, dispatchVirtualBlur as $4ELxY$dispatchVirtualBlur} from "@react-aria/focus";
4
- import {getInteractionModality as $4ELxY$getInteractionModality} from "@react-aria/interactions";
5
- import {useRef as $4ELxY$useRef, useEffect as $4ELxY$useEffect, useCallback as $4ELxY$useCallback, useMemo as $4ELxY$useMemo} from "react";
4
+ import {getInteractionModality as $4ELxY$getInteractionModality, getPointerType as $4ELxY$getPointerType} from "@react-aria/interactions";
5
+ import {useRef as $4ELxY$useRef, useState as $4ELxY$useState, useEffect as $4ELxY$useEffect, useCallback as $4ELxY$useCallback, useMemo as $4ELxY$useMemo} from "react";
6
6
  import {useLocalizedStringFormatter as $4ELxY$useLocalizedStringFormatter} from "@react-aria/i18n";
7
7
 
8
8
 
@@ -27,21 +27,24 @@ function $parcel$interopDefault(a) {
27
27
 
28
28
  function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
29
29
  let { inputRef: inputRef, collectionRef: collectionRef, filter: filter, disableAutoFocusFirst: disableAutoFocusFirst = false, disableVirtualFocus: disableVirtualFocus = false } = props;
30
- let collectionId = (0, $4ELxY$useSlotId)();
30
+ let collectionId = (0, $4ELxY$useId)();
31
31
  let timeout = (0, $4ELxY$useRef)(undefined);
32
32
  let delayNextActiveDescendant = (0, $4ELxY$useRef)(false);
33
33
  let queuedActiveDescendant = (0, $4ELxY$useRef)(null);
34
- let lastCollectionNode = (0, $4ELxY$useRef)(null);
35
34
  // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
36
35
  // moving focus back to the subtriggers
37
36
  let isMobileScreenReader = (0, $4ELxY$getInteractionModality)() === 'virtual' && ((0, $4ELxY$isIOS)() || (0, $4ELxY$isAndroid)());
38
- let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;
37
+ let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = (0, $4ELxY$useState)(!isMobileScreenReader && !disableVirtualFocus);
38
+ // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input
39
+ // since it isn't attached to a filterable collection (e.g. Tabs)
40
+ let [hasCollection, setHasCollection] = (0, $4ELxY$useState)(false);
39
41
  (0, $4ELxY$useEffect)(()=>{
40
42
  return ()=>clearTimeout(timeout.current);
41
43
  }, []);
42
- let updateActiveDescendant = (0, $4ELxY$useEffectEvent)((e)=>{
44
+ let updateActiveDescendantEvent = (0, $4ELxY$useEffectEvent)((e)=>{
43
45
  // Ensure input is focused if the user clicks on the collection directly.
44
- if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4ELxY$getActiveElement)((0, $4ELxY$getOwnerDocument)(inputRef.current)) !== inputRef.current) inputRef.current.focus();
46
+ // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options
47
+ if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && (0, $4ELxY$getActiveElement)((0, $4ELxY$getOwnerDocument)(inputRef.current)) !== inputRef.current && (0, $4ELxY$getPointerType)() !== 'touch') inputRef.current.focus();
45
48
  let target = e.target;
46
49
  if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) return;
47
50
  clearTimeout(timeout.current);
@@ -65,27 +68,33 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
65
68
  }
66
69
  delayNextActiveDescendant.current = false;
67
70
  });
68
- let callbackRef = (0, $4ELxY$useCallback)((collectionNode)=>{
69
- var _lastCollectionNode_current;
70
- if (collectionNode != null) {
71
- var // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
72
- // of the letter you just typed. If we recieve another focus event then we clear the queued update
73
- // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
74
- // React 19's extra call of the callback ref in strict mode
75
- _lastCollectionNode_current1;
76
- (_lastCollectionNode_current1 = lastCollectionNode.current) === null || _lastCollectionNode_current1 === void 0 ? void 0 : _lastCollectionNode_current1.removeEventListener('focusin', updateActiveDescendant);
77
- lastCollectionNode.current = collectionNode;
78
- collectionNode.addEventListener('focusin', updateActiveDescendant);
79
- } else (_lastCollectionNode_current = lastCollectionNode.current) === null || _lastCollectionNode_current === void 0 ? void 0 : _lastCollectionNode_current.removeEventListener('focusin', updateActiveDescendant);
71
+ let [collectionNode, setCollectionNode] = (0, $4ELxY$useState)(null);
72
+ let callbackRef = (0, $4ELxY$useCallback)((node)=>{
73
+ setCollectionNode(node);
74
+ if (node != null) {
75
+ // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it
76
+ // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless
77
+ // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.
78
+ if (node.getAttribute('tabindex') != null) setShouldUseVirtualFocus(false);
79
+ setHasCollection(true);
80
+ } else setHasCollection(false);
81
+ }, []);
82
+ (0, $4ELxY$useLayoutEffect)(()=>{
83
+ if (collectionNode != null) // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
84
+ // of the letter you just typed. If we recieve another focus event then we clear the queued update
85
+ collectionNode.addEventListener('focusin', updateActiveDescendantEvent);
86
+ return ()=>{
87
+ collectionNode === null || collectionNode === void 0 ? void 0 : collectionNode.removeEventListener('focusin', updateActiveDescendantEvent);
88
+ };
80
89
  }, [
81
- updateActiveDescendant
90
+ collectionNode
82
91
  ]);
83
92
  // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
84
93
  let mergedCollectionRef = (0, $4ELxY$useObjectRef)((0, $4ELxY$useMemo)(()=>(0, $4ELxY$mergeRefs)(collectionRef, callbackRef), [
85
94
  collectionRef,
86
95
  callbackRef
87
96
  ]));
88
- let focusFirstItem = (0, $4ELxY$useEffectEvent)(()=>{
97
+ let focusFirstItem = (0, $4ELxY$useCallback)(()=>{
89
98
  var _collectionRef_current;
90
99
  delayNextActiveDescendant.current = true;
91
100
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new CustomEvent((0, $4ELxY$FOCUS_EVENT), {
@@ -95,8 +104,10 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
95
104
  focusStrategy: 'first'
96
105
  }
97
106
  }));
98
- });
99
- let clearVirtualFocus = (0, $4ELxY$useEffectEvent)((clearFocusKey)=>{
107
+ }, [
108
+ collectionRef
109
+ ]);
110
+ let clearVirtualFocus = (0, $4ELxY$useCallback)((clearFocusKey)=>{
100
111
  var _collectionRef_current;
101
112
  (0, $4ELxY$moveVirtualFocus)((0, $4ELxY$getActiveElement)());
102
113
  queuedActiveDescendant.current = null;
@@ -111,7 +122,10 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
111
122
  clearTimeout(timeout.current);
112
123
  delayNextActiveDescendant.current = false;
113
124
  (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(clearFocusEvent);
114
- });
125
+ }, [
126
+ collectionRef,
127
+ state
128
+ ]);
115
129
  let lastInputType = (0, $4ELxY$useRef)('');
116
130
  (0, $4ELxY$useEvent)(inputRef, 'input', (e)=>{
117
131
  let { inputType: inputType } = e;
@@ -198,7 +212,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
198
212
  // Trigger click action on item when Enter key was pressed.
199
213
  if (focusedNodeId != null) {
200
214
  let item = document.getElementById(focusedNodeId);
201
- item === null || item === void 0 ? void 0 : item.click();
215
+ item === null || item === void 0 ? void 0 : item.dispatchEvent(new PointerEvent('click', e.nativeEvent));
202
216
  }
203
217
  break;
204
218
  }
@@ -225,9 +239,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
225
239
  return ()=>{
226
240
  document.removeEventListener('keyup', onKeyUpCapture, true);
227
241
  };
228
- }, [
229
- onKeyUpCapture
230
- ]);
242
+ }, []);
231
243
  let stringFormatter = (0, $4ELxY$useLocalizedStringFormatter)((0, ($parcel$interopDefault($4ELxY$intlStringsmodulejs))), '@react-aria/autocomplete');
232
244
  let collectionProps = (0, $4ELxY$useLabels)({
233
245
  id: collectionId,
@@ -272,7 +284,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
272
284
  onBlur: onBlur,
273
285
  onFocus: onFocus
274
286
  };
275
- if (collectionId) inputProps = {
287
+ if (hasCollection) inputProps = {
276
288
  ...inputProps,
277
289
  ...shouldUseVirtualFocus && virtualFocusProps,
278
290
  enterKeyHint: 'go',
@@ -289,7 +301,7 @@ function $48f6ba390f8c5b59$export$1e40b3ca02d92d21(props, state) {
289
301
  inputProps: inputProps,
290
302
  collectionProps: (0, $4ELxY$mergeProps)(collectionProps, {
291
303
  shouldUseVirtualFocus: shouldUseVirtualFocus,
292
- disallowTypeAhead: true
304
+ disallowTypeAhead: shouldUseVirtual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,SAAS,EACd;QAGF,IAAI,kBAAkB,uBAAuB,OAAO,GAAG,SAAS,cAAc,CAAC,uBAAuB,OAAO,IAAI;QACjH,IAAI,iBACF,CAAA,GAAA,0BAAkB,EAAE,iBAAiB,EAAE,aAAa;IAExD;IAEA,IAAI,UAAU,CAAC;QACb,IAAI,CAAC,EAAE,SAAS,EACd;QAGF,IAAI,iBAAiB,uBAAuB,OAAO,GAAG,SAAS,cAAc,CAAC,uBAAuB,OAAO,IAAI;QAChH,IAAI,gBAAgB;YAClB,IAAI,SAAS,EAAE,MAAM;YACrB,eAAe;gBACb,kKAAkK;gBAClK,CAAA,GAAA,0BAAkB,EAAE,QAAQ,cAAc,OAAO;gBACjD,CAAA,GAAA,2BAAmB,EAAE,cAAc,OAAO,EAAG;YAC/C;QACF;IACF;IAEA,uGAAuG;IACvG,uDAAuD;IACvD,IAAI,aAAa;QACf,OAAO,MAAM,UAAU;kBACvB;IACF;QAI2B;IAF3B,IAAI,oBAAoB;mBACtB;QACA,yBAAyB,CAAA,uBAAA,MAAM,aAAa,cAAnB,kCAAA,uBAAuB;gBAChD;iBACA;IACF;IAEA,IAAI,cACF,aAAa;QACX,GAAG,UAAU;QACb,GAAI,yBAAyB,iBAAiB;QAC9C,cAAc;QACd,iBAAiB;QACjB,mFAAmF;QACnF,qBAAqB;QACrB,qGAAqG;QACrG,aAAa;QACb,gEAAgE;QAChE,YAAY;QACZ,cAAc;IAChB;IAGF,OAAO;oBACL;QACA,iBAAiB,CAAA,GAAA,iBAAS,EAAE,iBAAiB;mCAC3C;YACA,mBAAmB;QACrB;QACA,eAAe;QACf,QAAQ,UAAU,OAAO,WAAW;IACtC;AACF","sources":["packages/@react-aria/autocomplete/src/useAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';\nimport {AriaTextFieldProps} from '@react-aria/textfield';\nimport {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';\nimport {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';\nimport {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';\nimport {getInteractionModality} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface CollectionOptions extends DOMProps, AriaLabelingProps {\n /** Whether the collection items should use virtual focus instead of being focused directly. */\n shouldUseVirtualFocus: boolean,\n /** Whether typeahead is disabled. */\n disallowTypeAhead: boolean\n}\n\nexport interface InputProps<T = FocusableElement> extends DOMProps,\n FocusEvents<T>,\n KeyboardEvents,\n Pick<ValueBase<string>, 'onChange' | 'value'>,\n Pick<AriaTextFieldProps, 'enterKeyHint' | 'aria-controls' | 'aria-autocomplete' | 'aria-activedescendant' | 'spellCheck' | 'autoCorrect' | 'autoComplete'> {}\n\nexport interface AriaAutocompleteProps<T> extends AutocompleteProps {\n /**\n * An optional filter function used to determine if a option should be included in the autocomplete list.\n * Include this if the items you are providing to your wrapped collection aren't filtered by default.\n */\n filter?: (textValue: string, inputValue: string, node: Node<T>) => boolean,\n\n /**\n * Whether or not to focus the first item in the collection after a filter is performed. Note this is only applicable\n * if virtual focus behavior is not turned off via `disableVirtualFocus`.\n * @default false\n */\n disableAutoFocusFirst?: boolean,\n\n /**\n * Whether the autocomplete should disable virtual focus, instead making the wrapped collection directly tabbable.\n * @default false\n */\n disableVirtualFocus?: boolean\n}\n\nexport interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T>, 'children'> {\n /** The ref for the wrapped collection element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the wrapped collection element. */\n collectionRef: RefObject<HTMLElement | null>\n}\n\nexport interface AutocompleteAria<T> {\n /** Props for the autocomplete input element. These should be passed to the input's aria hooks (e.g. useTextField/useSearchField/etc) respectively. */\n inputProps: InputProps,\n /** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */\n collectionProps: CollectionOptions,\n /** Ref to attach to the wrapped collection. */\n collectionRef: RefObject<HTMLElement | null>,\n /** A filter function that returns if the provided collection node should be filtered out of the collection. */\n filter?: (nodeTextValue: string, node: Node<T>) => boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an autocomplete component.\n * An autocomplete combines a text input with a collection, allowing users to filter the collection's contents match a query.\n * @param props - Props for the autocomplete.\n * @param state - State for the autocomplete, as returned by `useAutocompleteState`.\n */\nexport function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: AutocompleteState): AutocompleteAria<T> {\n let {\n inputRef,\n collectionRef,\n filter,\n disableAutoFocusFirst = false,\n disableVirtualFocus = false\n } = props;\n\n let collectionId = useSlotId();\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let delayNextActiveDescendant = useRef(false);\n let queuedActiveDescendant = useRef<string | null>(null);\n let lastCollectionNode = useRef<HTMLElement>(null);\n\n // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually\n // moving focus back to the subtriggers\n let isMobileScreenReader = getInteractionModality() === 'virtual' && (isIOS() || isAndroid());\n let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;\n useEffect(() => {\n return () => clearTimeout(timeout.current);\n }, []);\n\n let updateActiveDescendant = useEffectEvent((e: Event) => {\n // Ensure input is focused if the user clicks on the collection directly.\n if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {\n inputRef.current.focus();\n }\n\n let target = e.target as Element | null;\n if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {\n return;\n }\n\n clearTimeout(timeout.current);\n if (target !== collectionRef.current) {\n if (delayNextActiveDescendant.current) {\n queuedActiveDescendant.current = target.id;\n timeout.current = setTimeout(() => {\n state.setFocusedNodeId(target.id);\n }, 500);\n } else {\n queuedActiveDescendant.current = target.id;\n state.setFocusedNodeId(target.id);\n }\n } else if (queuedActiveDescendant.current && !document.getElementById(queuedActiveDescendant.current)) {\n // If we recieve a focus event refocusing the collection, either we have newly refocused the input and are waiting for the\n // wrapped collection to refocus the previously focused node if any OR\n // we are in a state where we've filtered to such a point that there aren't any matching items in the collection to focus.\n // In this case we want to clear tracked item if any and clear active descendant\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n }\n\n delayNextActiveDescendant.current = false;\n });\n\n let callbackRef = useCallback((collectionNode) => {\n if (collectionNode != null) {\n // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement\n // of the letter you just typed. If we recieve another focus event then we clear the queued update\n // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles\n // React 19's extra call of the callback ref in strict mode\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n lastCollectionNode.current = collectionNode;\n collectionNode.addEventListener('focusin', updateActiveDescendant);\n } else {\n lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);\n }\n }, [updateActiveDescendant]);\n\n // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection\n let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));\n\n let focusFirstItem = useEffectEvent(() => {\n delayNextActiveDescendant.current = true;\n collectionRef.current?.dispatchEvent(\n new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n focusStrategy: 'first'\n }\n })\n );\n });\n\n let clearVirtualFocus = useEffectEvent((clearFocusKey?: boolean) => {\n moveVirtualFocus(getActiveElement());\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n let clearFocusEvent = new CustomEvent(CLEAR_FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n clearFocusKey\n }\n });\n clearTimeout(timeout.current);\n delayNextActiveDescendant.current = false;\n collectionRef.current?.dispatchEvent(clearFocusEvent);\n });\n\n let lastInputType = useRef('');\n useEvent(inputRef, 'input', e => {\n let {inputType} = e as InputEvent;\n lastInputType.current = inputType;\n });\n\n let onChange = (value: string) => {\n // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when modifying the text via\n // copy paste/backspacing/undo/redo for screen reader announcements\n if (lastInputType.current === 'insertText' && !disableAutoFocusFirst) {\n focusFirstItem();\n } else if (lastInputType.current && (lastInputType.current.includes('insert') || lastInputType.current.includes('delete') || lastInputType.current.includes('history'))) {\n clearVirtualFocus(true);\n\n // If onChange was triggered before the timeout actually updated the activedescendant, we need to fire\n // our own dispatchVirtualFocus so focusVisible gets reapplied on the input\n if (getVirtuallyFocusedElement(document) === inputRef.current) {\n dispatchVirtualFocus(inputRef.current!, null);\n }\n }\n\n state.setInputValue(value);\n };\n\n let keyDownTarget = useRef<Element | null>(null);\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {\n keyDownTarget.current = e.target as Element;\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n let focusedNodeId = queuedActiveDescendant.current;\n switch (e.key) {\n case 'a':\n if (isCtrlKeyPressed(e)) {\n return;\n }\n break;\n case 'Escape':\n // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and\n // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check\n // for isPropagationStopped\n if (e.isDefaultPrevented()) {\n return;\n }\n break;\n case ' ':\n // Space shouldn't trigger onAction so early return.\n return;\n case 'Tab':\n // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)\n // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n return;\n case 'Home':\n case 'End':\n case 'PageDown':\n case 'PageUp':\n case 'ArrowUp':\n case 'ArrowDown': {\n if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) {\n return;\n }\n\n // Prevent these keys from moving the text cursor in the input\n e.preventDefault();\n // Move virtual focus into the wrapped collection\n let focusCollection = new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true\n });\n\n collectionRef.current?.dispatchEvent(focusCollection);\n break;\n }\n }\n\n // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter\n // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events\n // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble\n // as expected\n if (!e.isPropagationStopped()) {\n e.stopPropagation();\n }\n\n let shouldPerformDefaultAction = true;\n if (collectionRef.current !== null) {\n if (focusedNodeId == null) {\n shouldPerformDefaultAction = collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n } else {\n let item = document.getElementById(focusedNodeId);\n if (item) {\n shouldPerformDefaultAction = item?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n }\n }\n }\n\n if (shouldPerformDefaultAction) {\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowRight': {\n // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the\n // user's keyboard navigation restarts from where they left off\n clearVirtualFocus();\n break;\n }\n case 'Enter':\n // Trigger click action on item when Enter key was pressed.\n if (focusedNodeId != null) {\n let item = document.getElementById(focusedNodeId);\n item?.click();\n }\n break;\n }\n } else {\n // TODO: check if we can do this, want to stop textArea from using its default Enter behavior so items are properly triggered\n e.preventDefault();\n }\n };\n\n let onKeyUpCapture = useEffectEvent((e) => {\n // Dispatch simulated key up events for things like triggering links in listbox\n // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair\n // is detected by usePress instead of the original keyup originating from the input\n if (e.target === keyDownTarget.current) {\n e.stopImmediatePropagation();\n let focusedNodeId = queuedActiveDescendant.current;\n if (focusedNodeId == null) {\n collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n } else {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n }\n });\n\n useEffect(() => {\n document.addEventListener('keyup', onKeyUpCapture, true);\n return () => {\n document.removeEventListener('keyup', onKeyUpCapture, true);\n };\n }, [onKeyUpCapture]);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');\n let collectionProps = useLabels({\n id: collectionId,\n 'aria-label': stringFormatter.format('collectionLabel')\n });\n\n let filterFn = useCallback((nodeTextValue: string, node: Node<T>) => {\n if (filter) {\n return filter(nodeTextValue, state.inputValue, node);\n }\n\n return true;\n }, [state.inputValue, filter]);\n\n // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the\n // focus ring on the virtually focused collection when are actually interacting with the Autocomplete\n let onBlur = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (lastFocusedNode) {\n dispatchVirtualBlur(lastFocusedNode, e.relatedTarget);\n }\n };\n\n let onFocus = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (curFocusedNode) {\n let target = e.target;\n queueMicrotask(() => {\n // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item\n dispatchVirtualBlur(target, collectionRef.current);\n dispatchVirtualFocus(collectionRef.current!, target);\n });\n }\n };\n\n // Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually\n // being filtered/allows filtering by the Autocomplete.\n let inputProps = {\n value: state.inputValue,\n onChange\n } as AriaTextFieldProps<FocusableElement>;\n\n let virtualFocusProps = {\n onKeyDown,\n 'aria-activedescendant': state.focusedNodeId ?? undefined,\n onBlur,\n onFocus\n };\n\n if (collectionId) {\n inputProps = {\n ...inputProps,\n ...(shouldUseVirtualFocus && virtualFocusProps),\n enterKeyHint: 'go',\n 'aria-controls': collectionId,\n // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n 'aria-autocomplete': 'list',\n // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.\n autoCorrect: 'off',\n // This disable's the macOS Safari spell check auto corrections.\n spellCheck: 'false',\n autoComplete: 'off'\n };\n }\n\n return {\n inputProps,\n collectionProps: mergeProps(collectionProps, {\n shouldUseVirtualFocus,\n disallowTypeAhead: true\n }),\n collectionRef: mergedCollectionRef,\n filter: filter != null ? filterFn : undefined\n };\n}\n"],"names":[],"version":3,"file":"useAutocomplete.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAuEM,SAAS,0CAAmB,KAAiC,EAAE,KAAwB;IAC5F,IAAI,YACF,QAAQ,iBACR,aAAa,UACb,MAAM,yBACN,wBAAwB,4BACxB,sBAAsB,OACvB,GAAG;IAEJ,IAAI,eAAe,CAAA,GAAA,YAAI;IACvB,IAAI,UAAU,CAAA,GAAA,aAAK,EAA6C;IAChE,IAAI,4BAA4B,CAAA,GAAA,aAAK,EAAE;IACvC,IAAI,yBAAyB,CAAA,GAAA,aAAK,EAAiB;IAEnD,2HAA2H;IAC3H,uCAAuC;IACvC,IAAI,uB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a;IAExD;IAEA,IAAI,UAAU,CAAC;QACb,IAAI,CAAC,EAAE,SAAS,EACd;QAGF,IAAI,iBAAiB,uBAAuB,OAAO,GAAG,SAAS,cAAc,CAAC,uBAAuB,OAAO,IAAI;QAChH,IAAI,gBAAgB;YAClB,IAAI,SAAS,EAAE,MAAM;YACrB,eAAe;gBACb,kKAAkK;gBAClK,CAAA,GAAA,0BAAkB,EAAE,QAAQ,cAAc,OAAO;gBACjD,CAAA,GAAA,2BAAmB,EAAE,cAAc,OAAO,EAAG;YAC/C;QACF;IACF;IAEA,uGAAuG;IACvG,uDAAuD;IACvD,IAAI,aAAa;QACf,OAAO,MAAM,UAAU;kBACvB;IACF;QAI2B;IAF3B,IAAI,oBAAoB;mBACtB;QACA,yBAAyB,CAAA,uBAAA,MAAM,aAAa,cAAnB,kCAAA,uBAAuB;gBAChD;iBACA;IACF;IAEA,IAAI,eACF,aAAa;QACX,GAAG,UAAU;QACb,GAAI,yBAAyB,iBAAiB;QAC9C,cAAc;QACd,iBAAiB;QACjB,mFAAmF;QACnF,qBAAqB;QACrB,qGAAqG;QACrG,aAAa;QACb,gEAAgE;QAChE,YAAY;QACZ,cAAc;IAChB;IAGF,OAAO;oBACL;QACA,iBAAiB,CAAA,GAAA,iBAAS,EAAE,iBAAiB;mCAC3C;YACA,mBAAmB;QACrB;QACA,eAAe;QACf,QAAQ,UAAU,OAAO,WAAW;IACtC;AACF","sources":["packages/@react-aria/autocomplete/src/useAutocomplete.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';\nimport {AriaTextFieldProps} from '@react-aria/textfield';\nimport {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';\nimport {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useId, useLabels, useLayoutEffect, useObjectRef} from '@react-aria/utils';\nimport {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';\nimport {getInteractionModality, getPointerType} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface CollectionOptions extends DOMProps, AriaLabelingProps {\n /** Whether the collection items should use virtual focus instead of being focused directly. */\n shouldUseVirtualFocus: boolean,\n /** Whether typeahead is disabled. */\n disallowTypeAhead: boolean\n}\n\nexport interface InputProps<T = FocusableElement> extends DOMProps,\n FocusEvents<T>,\n KeyboardEvents,\n Pick<ValueBase<string>, 'onChange' | 'value'>,\n Pick<AriaTextFieldProps, 'enterKeyHint' | 'aria-controls' | 'aria-autocomplete' | 'aria-activedescendant' | 'spellCheck' | 'autoCorrect' | 'autoComplete'> {}\n\nexport interface AriaAutocompleteProps<T> extends AutocompleteProps {\n /**\n * An optional filter function used to determine if a option should be included in the autocomplete list.\n * Include this if the items you are providing to your wrapped collection aren't filtered by default.\n */\n filter?: (textValue: string, inputValue: string, node: Node<T>) => boolean,\n\n /**\n * Whether or not to focus the first item in the collection after a filter is performed. Note this is only applicable\n * if virtual focus behavior is not turned off via `disableVirtualFocus`.\n * @default false\n */\n disableAutoFocusFirst?: boolean,\n\n /**\n * Whether the autocomplete should disable virtual focus, instead making the wrapped collection directly tabbable.\n * @default false\n */\n disableVirtualFocus?: boolean\n}\n\nexport interface AriaAutocompleteOptions<T> extends Omit<AriaAutocompleteProps<T>, 'children'> {\n /** The ref for the wrapped collection element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the wrapped collection element. */\n collectionRef: RefObject<HTMLElement | null>\n}\n\nexport interface AutocompleteAria<T> {\n /** Props for the autocomplete input element. These should be passed to the input's aria hooks (e.g. useTextField/useSearchField/etc) respectively. */\n inputProps: InputProps,\n /** Props for the collection, to be passed to collection's respective aria hook (e.g. useMenu). */\n collectionProps: CollectionOptions,\n /** Ref to attach to the wrapped collection. */\n collectionRef: RefObject<HTMLElement | null>,\n /** A filter function that returns if the provided collection node should be filtered out of the collection. */\n filter?: (nodeTextValue: string, node: Node<T>) => boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for an autocomplete component.\n * An autocomplete combines a text input with a collection, allowing users to filter the collection's contents match a query.\n * @param props - Props for the autocomplete.\n * @param state - State for the autocomplete, as returned by `useAutocompleteState`.\n */\nexport function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: AutocompleteState): AutocompleteAria<T> {\n let {\n inputRef,\n collectionRef,\n filter,\n disableAutoFocusFirst = false,\n disableVirtualFocus = false\n } = props;\n\n let collectionId = useId();\n let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let delayNextActiveDescendant = useRef(false);\n let queuedActiveDescendant = useRef<string | null>(null);\n\n // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually\n // moving focus back to the subtriggers\n let isMobileScreenReader = getInteractionModality() === 'virtual' && (isIOS() || isAndroid());\n let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = useState(!isMobileScreenReader && !disableVirtualFocus);\n // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input\n // since it isn't attached to a filterable collection (e.g. Tabs)\n let [hasCollection, setHasCollection] = useState(false);\n\n useEffect(() => {\n return () => clearTimeout(timeout.current);\n }, []);\n\n let updateActiveDescendantEvent = useEffectEvent((e: Event) => {\n // Ensure input is focused if the user clicks on the collection directly.\n // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options\n if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current && getPointerType() !== 'touch') {\n inputRef.current.focus();\n }\n\n let target = e.target as Element | null;\n if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) {\n return;\n }\n\n clearTimeout(timeout.current);\n if (target !== collectionRef.current) {\n if (delayNextActiveDescendant.current) {\n queuedActiveDescendant.current = target.id;\n timeout.current = setTimeout(() => {\n state.setFocusedNodeId(target.id);\n }, 500);\n } else {\n queuedActiveDescendant.current = target.id;\n state.setFocusedNodeId(target.id);\n }\n } else if (queuedActiveDescendant.current && !document.getElementById(queuedActiveDescendant.current)) {\n // If we recieve a focus event refocusing the collection, either we have newly refocused the input and are waiting for the\n // wrapped collection to refocus the previously focused node if any OR\n // we are in a state where we've filtered to such a point that there aren't any matching items in the collection to focus.\n // In this case we want to clear tracked item if any and clear active descendant\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n }\n\n delayNextActiveDescendant.current = false;\n });\n\n let [collectionNode, setCollectionNode] = useState<HTMLElement | null>(null);\n let callbackRef = useCallback((node) => {\n setCollectionNode(node);\n if (node != null) {\n // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it\n // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless\n // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.\n if (node.getAttribute('tabindex') != null) {\n setShouldUseVirtualFocus(false);\n }\n setHasCollection(true);\n } else {\n setHasCollection(false);\n }\n }, []);\n useLayoutEffect(() => {\n if (collectionNode != null) {\n // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement\n // of the letter you just typed. If we recieve another focus event then we clear the queued update\n collectionNode.addEventListener('focusin', updateActiveDescendantEvent);\n }\n return () => {\n collectionNode?.removeEventListener('focusin', updateActiveDescendantEvent);\n };\n }, [collectionNode]);\n\n // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection\n let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));\n\n let focusFirstItem = useCallback(() => {\n delayNextActiveDescendant.current = true;\n collectionRef.current?.dispatchEvent(\n new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n focusStrategy: 'first'\n }\n })\n );\n }, [collectionRef]);\n\n let clearVirtualFocus = useCallback((clearFocusKey?: boolean) => {\n moveVirtualFocus(getActiveElement());\n queuedActiveDescendant.current = null;\n state.setFocusedNodeId(null);\n let clearFocusEvent = new CustomEvent(CLEAR_FOCUS_EVENT, {\n cancelable: true,\n bubbles: true,\n detail: {\n clearFocusKey\n }\n });\n clearTimeout(timeout.current);\n delayNextActiveDescendant.current = false;\n collectionRef.current?.dispatchEvent(clearFocusEvent);\n }, [collectionRef, state]);\n\n let lastInputType = useRef('');\n useEvent(inputRef, 'input', e => {\n let {inputType} = e as InputEvent;\n lastInputType.current = inputType;\n });\n\n let onChange = (value: string) => {\n // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when modifying the text via\n // copy paste/backspacing/undo/redo for screen reader announcements\n if (lastInputType.current === 'insertText' && !disableAutoFocusFirst) {\n focusFirstItem();\n } else if (lastInputType.current && (lastInputType.current.includes('insert') || lastInputType.current.includes('delete') || lastInputType.current.includes('history'))) {\n clearVirtualFocus(true);\n\n // If onChange was triggered before the timeout actually updated the activedescendant, we need to fire\n // our own dispatchVirtualFocus so focusVisible gets reapplied on the input\n if (getVirtuallyFocusedElement(document) === inputRef.current) {\n dispatchVirtualFocus(inputRef.current!, null);\n }\n }\n\n state.setInputValue(value);\n };\n\n let keyDownTarget = useRef<Element | null>(null);\n // For textfield specific keydown operations\n let onKeyDown = (e: BaseEvent<ReactKeyboardEvent<any>>) => {\n keyDownTarget.current = e.target as Element;\n if (e.nativeEvent.isComposing) {\n return;\n }\n\n let focusedNodeId = queuedActiveDescendant.current;\n switch (e.key) {\n case 'a':\n if (isCtrlKeyPressed(e)) {\n return;\n }\n break;\n case 'Escape':\n // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and\n // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check\n // for isPropagationStopped\n if (e.isDefaultPrevented()) {\n return;\n }\n break;\n case ' ':\n // Space shouldn't trigger onAction so early return.\n return;\n case 'Tab':\n // Don't propogate Tab down to the collection, otherwise we will try to focus the collection via useSelectableCollection's Tab handler (aka shift tab logic)\n // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate\n if ('continuePropagation' in e) {\n e.continuePropagation();\n }\n return;\n case 'Home':\n case 'End':\n case 'PageDown':\n case 'PageUp':\n case 'ArrowUp':\n case 'ArrowDown': {\n if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) {\n return;\n }\n\n // Prevent these keys from moving the text cursor in the input\n e.preventDefault();\n // Move virtual focus into the wrapped collection\n let focusCollection = new CustomEvent(FOCUS_EVENT, {\n cancelable: true,\n bubbles: true\n });\n\n collectionRef.current?.dispatchEvent(focusCollection);\n break;\n }\n }\n\n // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter\n // or moving focus from one item to another. Stop propagation on the input event if it isn't already stopped so it doesn't leak out. For events\n // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble\n // as expected\n if (!e.isPropagationStopped()) {\n e.stopPropagation();\n }\n\n let shouldPerformDefaultAction = true;\n if (collectionRef.current !== null) {\n if (focusedNodeId == null) {\n shouldPerformDefaultAction = collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n } else {\n let item = document.getElementById(focusedNodeId);\n if (item) {\n shouldPerformDefaultAction = item?.dispatchEvent(\n new KeyboardEvent(e.nativeEvent.type, e.nativeEvent)\n ) || false;\n }\n }\n }\n\n if (shouldPerformDefaultAction) {\n switch (e.key) {\n case 'ArrowLeft':\n case 'ArrowRight': {\n // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the\n // user's keyboard navigation restarts from where they left off\n clearVirtualFocus();\n break;\n }\n case 'Enter':\n // Trigger click action on item when Enter key was pressed.\n if (focusedNodeId != null) {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(new PointerEvent('click', e.nativeEvent));\n }\n break;\n }\n } else {\n // TODO: check if we can do this, want to stop textArea from using its default Enter behavior so items are properly triggered\n e.preventDefault();\n }\n };\n\n let onKeyUpCapture = useEffectEvent((e) => {\n // Dispatch simulated key up events for things like triggering links in listbox\n // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair\n // is detected by usePress instead of the original keyup originating from the input\n if (e.target === keyDownTarget.current) {\n e.stopImmediatePropagation();\n let focusedNodeId = queuedActiveDescendant.current;\n if (focusedNodeId == null) {\n collectionRef.current?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n } else {\n let item = document.getElementById(focusedNodeId);\n item?.dispatchEvent(\n new KeyboardEvent(e.type, e)\n );\n }\n }\n });\n\n useEffect(() => {\n document.addEventListener('keyup', onKeyUpCapture, true);\n return () => {\n document.removeEventListener('keyup', onKeyUpCapture, true);\n };\n }, []);\n\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');\n let collectionProps = useLabels({\n id: collectionId,\n 'aria-label': stringFormatter.format('collectionLabel')\n });\n\n let filterFn = useCallback((nodeTextValue: string, node: Node<T>) => {\n if (filter) {\n return filter(nodeTextValue, state.inputValue, node);\n }\n\n return true;\n }, [state.inputValue, filter]);\n\n // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the\n // focus ring on the virtually focused collection when are actually interacting with the Autocomplete\n let onBlur = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (lastFocusedNode) {\n dispatchVirtualBlur(lastFocusedNode, e.relatedTarget);\n }\n };\n\n let onFocus = (e: ReactFocusEvent) => {\n if (!e.isTrusted) {\n return;\n }\n\n let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;\n if (curFocusedNode) {\n let target = e.target;\n queueMicrotask(() => {\n // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item\n dispatchVirtualBlur(target, collectionRef.current);\n dispatchVirtualFocus(collectionRef.current!, target);\n });\n }\n };\n\n // Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually\n // being filtered/allows filtering by the Autocomplete.\n let inputProps = {\n value: state.inputValue,\n onChange\n } as AriaTextFieldProps<FocusableElement>;\n\n let virtualFocusProps = {\n onKeyDown,\n 'aria-activedescendant': state.focusedNodeId ?? undefined,\n onBlur,\n onFocus\n };\n\n if (hasCollection) {\n inputProps = {\n ...inputProps,\n ...(shouldUseVirtualFocus && virtualFocusProps),\n enterKeyHint: 'go',\n 'aria-controls': collectionId,\n // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)\n 'aria-autocomplete': 'list',\n // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.\n autoCorrect: 'off',\n // This disable's the macOS Safari spell check auto corrections.\n spellCheck: 'false',\n autoComplete: 'off'\n };\n }\n\n return {\n inputProps,\n collectionProps: mergeProps(collectionProps, {\n shouldUseVirtualFocus,\n disallowTypeAhead: shouldUseVirtualFocus\n }),\n collectionRef: mergedCollectionRef,\n filter: filter != null ? filterFn : undefined\n };\n}\n"],"names":[],"version":3,"file":"useAutocomplete.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,0CAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,oCAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search 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 search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,0CAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,oCAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,gCAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the list box, to be passed to `useListBox`. */\n listBoxProps: AriaListBoxOptions<T>,\n /** Props for the search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,kBAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search 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 search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAkDM,SAAS,0CAAyB,KAAuC,EAAE,KAAuB;IACvG,IAAI,cACF,UAAU,YACV,QAAQ,cACR,UAAU,oBACV,gBAAgB,kBAChB,cAAc,YACd,WAAW,KAAO,YAClB,OAAO,aACP,SAAS,WACT,OAAO,aACP,SAAS,mBACT,eAAe,sBACf,kBAAkB,cAClB,UAAU,EACV,GAAG,YACJ,GAAG;IAEJ,IAAI,cAAC,UAAU,oBAAE,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QAClD,GAAG,UAAU;QACb,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;QAC7B,cAAc;QACd,SAAS;YACP,MAAM,aAAa,CAAC;YACpB,IAAI,SACF;QAEJ;QACA,UAAU,CAAC;YACT,iEAAiE;YACjE,IAAI,MAAM,gBAAgB,CAAC,UAAU,KAAK,MACxC,SAAS,OAAO;QAEpB;mBACA;iBACA;IACF,GAAG;QACD,OAAO,MAAM,UAAU;QACvB,UAAU,MAAM,aAAa;IAC/B,GAAG;IAGH,IAAI,gBAAC,YAAY,cAAE,UAAU,EAAE,YAAY,kBAAkB,EAAE,GAAG,YAAW,GAAG,CAAA,GAAA,kBAAU,EACxF;QACE,GAAG,UAAU;0BACb;wBACA;oBACA;oBACA;kBACA;QACA,SAAS;QACT,eAAe;QACf,QAAQ;QACR,WAAW;QACX,SAAS;mBACT;yBACA;4BACA;oBACA;QACA,UAAU;IACZ,GACA;IAGF,OAAO;oBACL;QACA,YAAY,CAAA,GAAA,iBAAS,EAAE,YAAY;sBACnC;0BACA;QACA,GAAG,UAAU;IACf;AACF","sources":["packages/@react-aria/autocomplete/src/useSearchAutocomplete.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSearchAutocompleteProps} from '@react-types/autocomplete';\nimport {ComboBoxState} from '@react-stately/combobox';\nimport {DOMAttributes, KeyboardDelegate, LayoutDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {InputHTMLAttributes} from 'react';\nimport {mergeProps} from '@react-aria/utils';\nimport {useComboBox} from '@react-aria/combobox';\nimport {useSearchField} from '@react-aria/searchfield';\n\nexport interface SearchAutocompleteAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n /** Props for the search input element. */\n inputProps: InputHTMLAttributes<HTMLInputElement>,\n /** Props for the list box, to be passed to `useListBox`. */\n listBoxProps: AriaListBoxOptions<T>,\n /** Props for the search input's clear button. */\n clearButtonProps: AriaButtonProps,\n /** Props for the search autocomplete description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the search autocomplete error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaSearchAutocompleteOptions<T> extends AriaSearchAutocompleteProps<T> {\n /** The ref for the input element. */\n inputRef: RefObject<HTMLInputElement | null>,\n /** The ref for the list box popover. */\n popoverRef: RefObject<HTMLDivElement | null>,\n /** The ref for the list box. */\n listBoxRef: RefObject<HTMLElement | null>,\n /** An optional keyboard delegate implementation, to override the default. */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * A delegate object that provides layout information for items in the collection.\n * By default this uses the DOM, but this can be overridden to implement things like\n * virtualized scrolling.\n */\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * Provides the behavior and accessibility implementation for a search autocomplete component.\n * A search autocomplete combines a combobox with a searchfield, allowing users to filter a list of options to items matching a query.\n * @param props - Props for the search autocomplete.\n * @param state - State for the search autocomplete, as returned by `useSearchAutocomplete`.\n */\nexport function useSearchAutocomplete<T>(props: AriaSearchAutocompleteOptions<T>, state: ComboBoxState<T>): SearchAutocompleteAria<T> {\n let {\n popoverRef,\n inputRef,\n listBoxRef,\n keyboardDelegate,\n layoutDelegate,\n onSubmit = () => {},\n onClear,\n onKeyDown,\n onKeyUp,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n ...otherProps\n } = props;\n\n let {inputProps, clearButtonProps} = useSearchField({\n ...otherProps,\n value: state.inputValue,\n onChange: state.setInputValue,\n autoComplete: 'off',\n onClear: () => {\n state.setInputValue('');\n if (onClear) {\n onClear();\n }\n },\n onSubmit: (value) => {\n // Prevent submission from search field if menu item was selected\n if (state.selectionManager.focusedKey === null) {\n onSubmit(value, null);\n }\n },\n onKeyDown,\n onKeyUp\n }, {\n value: state.inputValue,\n setValue: state.setInputValue\n }, inputRef);\n\n\n let {listBoxProps, labelProps, inputProps: comboBoxInputProps, ...validation} = useComboBox(\n {\n ...otherProps,\n keyboardDelegate,\n layoutDelegate,\n popoverRef,\n listBoxRef,\n inputRef,\n onFocus: undefined,\n onFocusChange: undefined,\n onBlur: undefined,\n onKeyDown: undefined,\n onKeyUp: undefined,\n isInvalid,\n validationState,\n validationBehavior,\n isRequired,\n validate: undefined\n },\n state\n );\n\n return {\n labelProps,\n inputProps: mergeProps(inputProps, comboBoxInputProps),\n listBoxProps,\n clearButtonProps,\n ...validation\n };\n}\n"],"names":[],"version":3,"file":"useSearchAutocomplete.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/autocomplete",
3
- "version": "3.0.0-rc.2",
3
+ "version": "3.0.0-rc.4",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,19 +26,19 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/combobox": "^3.13.2",
30
- "@react-aria/focus": "^3.21.1",
31
- "@react-aria/i18n": "^3.12.12",
32
- "@react-aria/interactions": "^3.25.5",
33
- "@react-aria/listbox": "^3.14.8",
34
- "@react-aria/searchfield": "^3.8.8",
35
- "@react-aria/textfield": "^3.18.1",
36
- "@react-aria/utils": "^3.30.1",
37
- "@react-stately/autocomplete": "3.0.0-beta.3",
38
- "@react-stately/combobox": "^3.11.1",
39
- "@react-types/autocomplete": "3.0.0-alpha.34",
40
- "@react-types/button": "^3.14.0",
41
- "@react-types/shared": "^3.32.0",
29
+ "@react-aria/combobox": "^3.14.1",
30
+ "@react-aria/focus": "^3.21.3",
31
+ "@react-aria/i18n": "^3.12.14",
32
+ "@react-aria/interactions": "^3.26.0",
33
+ "@react-aria/listbox": "^3.15.1",
34
+ "@react-aria/searchfield": "^3.8.10",
35
+ "@react-aria/textfield": "^3.18.3",
36
+ "@react-aria/utils": "^3.32.0",
37
+ "@react-stately/autocomplete": "3.0.0-beta.4",
38
+ "@react-stately/combobox": "^3.12.1",
39
+ "@react-types/autocomplete": "3.0.0-alpha.36",
40
+ "@react-types/button": "^3.14.1",
41
+ "@react-types/shared": "^3.32.1",
42
42
  "@swc/helpers": "^0.5.0"
43
43
  },
44
44
  "peerDependencies": {
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "7bbe432a2f3ac09448b09769b34d36d777267f2f"
51
+ "gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
52
52
  }
@@ -13,12 +13,12 @@
13
13
  import {AriaLabelingProps, BaseEvent, DOMProps, FocusableElement, FocusEvents, KeyboardEvents, Node, RefObject, ValueBase} from '@react-types/shared';
14
14
  import {AriaTextFieldProps} from '@react-aria/textfield';
15
15
  import {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';
16
- import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useLabels, useObjectRef, useSlotId} from '@react-aria/utils';
16
+ import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, getActiveElement, getOwnerDocument, isAndroid, isCtrlKeyPressed, isIOS, mergeProps, mergeRefs, useEffectEvent, useEvent, useId, useLabels, useLayoutEffect, useObjectRef} from '@react-aria/utils';
17
17
  import {dispatchVirtualBlur, dispatchVirtualFocus, getVirtuallyFocusedElement, moveVirtualFocus} from '@react-aria/focus';
18
- import {getInteractionModality} from '@react-aria/interactions';
18
+ import {getInteractionModality, getPointerType} from '@react-aria/interactions';
19
19
  // @ts-ignore
20
20
  import intlMessages from '../intl/*.json';
21
- import {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef} from 'react';
21
+ import {FocusEvent as ReactFocusEvent, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef, useState} from 'react';
22
22
  import {useLocalizedStringFormatter} from '@react-aria/i18n';
23
23
 
24
24
  export interface CollectionOptions extends DOMProps, AriaLabelingProps {
@@ -88,23 +88,27 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
88
88
  disableVirtualFocus = false
89
89
  } = props;
90
90
 
91
- let collectionId = useSlotId();
91
+ let collectionId = useId();
92
92
  let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
93
93
  let delayNextActiveDescendant = useRef(false);
94
94
  let queuedActiveDescendant = useRef<string | null>(null);
95
- let lastCollectionNode = useRef<HTMLElement>(null);
96
95
 
97
96
  // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
98
97
  // moving focus back to the subtriggers
99
98
  let isMobileScreenReader = getInteractionModality() === 'virtual' && (isIOS() || isAndroid());
100
- let shouldUseVirtualFocus = !isMobileScreenReader && !disableVirtualFocus;
99
+ let [shouldUseVirtualFocus, setShouldUseVirtualFocus] = useState(!isMobileScreenReader && !disableVirtualFocus);
100
+ // Tracks if a collection has been connected to the autocomplete. If false, we don't want to add various attributes to the autocomplete input
101
+ // since it isn't attached to a filterable collection (e.g. Tabs)
102
+ let [hasCollection, setHasCollection] = useState(false);
103
+
101
104
  useEffect(() => {
102
105
  return () => clearTimeout(timeout.current);
103
106
  }, []);
104
107
 
105
- let updateActiveDescendant = useEffectEvent((e: Event) => {
108
+ let updateActiveDescendantEvent = useEffectEvent((e: Event) => {
106
109
  // Ensure input is focused if the user clicks on the collection directly.
107
- if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current) {
110
+ // don't trigger on touch so that mobile keyboard doesnt appear when tapping on options
111
+ if (!e.isTrusted && shouldUseVirtualFocus && inputRef.current && getActiveElement(getOwnerDocument(inputRef.current)) !== inputRef.current && getPointerType() !== 'touch') {
108
112
  inputRef.current.focus();
109
113
  }
110
114
 
@@ -136,24 +140,36 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
136
140
  delayNextActiveDescendant.current = false;
137
141
  });
138
142
 
139
- let callbackRef = useCallback((collectionNode) => {
143
+ let [collectionNode, setCollectionNode] = useState<HTMLElement | null>(null);
144
+ let callbackRef = useCallback((node) => {
145
+ setCollectionNode(node);
146
+ if (node != null) {
147
+ // If useSelectableCollection isn't passed shouldUseVirtualFocus even when useAutocomplete provides it
148
+ // that means the collection doesn't support it (e.g. Table). If that is the case, we need to disable it here regardless
149
+ // of what the user's provided so that the input doesn't recieve the onKeyDown and autocomplete props.
150
+ if (node.getAttribute('tabindex') != null) {
151
+ setShouldUseVirtualFocus(false);
152
+ }
153
+ setHasCollection(true);
154
+ } else {
155
+ setHasCollection(false);
156
+ }
157
+ }, []);
158
+ useLayoutEffect(() => {
140
159
  if (collectionNode != null) {
141
160
  // When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
142
161
  // of the letter you just typed. If we recieve another focus event then we clear the queued update
143
- // We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
144
- // React 19's extra call of the callback ref in strict mode
145
- lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);
146
- lastCollectionNode.current = collectionNode;
147
- collectionNode.addEventListener('focusin', updateActiveDescendant);
148
- } else {
149
- lastCollectionNode.current?.removeEventListener('focusin', updateActiveDescendant);
162
+ collectionNode.addEventListener('focusin', updateActiveDescendantEvent);
150
163
  }
151
- }, [updateActiveDescendant]);
164
+ return () => {
165
+ collectionNode?.removeEventListener('focusin', updateActiveDescendantEvent);
166
+ };
167
+ }, [collectionNode]);
152
168
 
153
169
  // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
154
170
  let mergedCollectionRef = useObjectRef(useMemo(() => mergeRefs(collectionRef, callbackRef), [collectionRef, callbackRef]));
155
171
 
156
- let focusFirstItem = useEffectEvent(() => {
172
+ let focusFirstItem = useCallback(() => {
157
173
  delayNextActiveDescendant.current = true;
158
174
  collectionRef.current?.dispatchEvent(
159
175
  new CustomEvent(FOCUS_EVENT, {
@@ -164,9 +180,9 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
164
180
  }
165
181
  })
166
182
  );
167
- });
183
+ }, [collectionRef]);
168
184
 
169
- let clearVirtualFocus = useEffectEvent((clearFocusKey?: boolean) => {
185
+ let clearVirtualFocus = useCallback((clearFocusKey?: boolean) => {
170
186
  moveVirtualFocus(getActiveElement());
171
187
  queuedActiveDescendant.current = null;
172
188
  state.setFocusedNodeId(null);
@@ -180,7 +196,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
180
196
  clearTimeout(timeout.current);
181
197
  delayNextActiveDescendant.current = false;
182
198
  collectionRef.current?.dispatchEvent(clearFocusEvent);
183
- });
199
+ }, [collectionRef, state]);
184
200
 
185
201
  let lastInputType = useRef('');
186
202
  useEvent(inputRef, 'input', e => {
@@ -299,7 +315,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
299
315
  // Trigger click action on item when Enter key was pressed.
300
316
  if (focusedNodeId != null) {
301
317
  let item = document.getElementById(focusedNodeId);
302
- item?.click();
318
+ item?.dispatchEvent(new PointerEvent('click', e.nativeEvent));
303
319
  }
304
320
  break;
305
321
  }
@@ -334,7 +350,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
334
350
  return () => {
335
351
  document.removeEventListener('keyup', onKeyUpCapture, true);
336
352
  };
337
- }, [onKeyUpCapture]);
353
+ }, []);
338
354
 
339
355
  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/autocomplete');
340
356
  let collectionProps = useLabels({
@@ -393,7 +409,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
393
409
  onFocus
394
410
  };
395
411
 
396
- if (collectionId) {
412
+ if (hasCollection) {
397
413
  inputProps = {
398
414
  ...inputProps,
399
415
  ...(shouldUseVirtualFocus && virtualFocusProps),
@@ -413,7 +429,7 @@ export function useAutocomplete<T>(props: AriaAutocompleteOptions<T>, state: Aut
413
429
  inputProps,
414
430
  collectionProps: mergeProps(collectionProps, {
415
431
  shouldUseVirtualFocus,
416
- disallowTypeAhead: true
432
+ disallowTypeAhead: shouldUseVirtualFocus
417
433
  }),
418
434
  collectionRef: mergedCollectionRef,
419
435
  filter: filter != null ? filterFn : undefined
@@ -25,7 +25,7 @@ export interface SearchAutocompleteAria<T> extends ValidationResult {
25
25
  labelProps: DOMAttributes,
26
26
  /** Props for the search input element. */
27
27
  inputProps: InputHTMLAttributes<HTMLInputElement>,
28
- /** Props for the list box, to be passed to [useListBox](useListBox.html). */
28
+ /** Props for the list box, to be passed to `useListBox`. */
29
29
  listBoxProps: AriaListBoxOptions<T>,
30
30
  /** Props for the search input's clear button. */
31
31
  clearButtonProps: AriaButtonProps,