@react-aria/autocomplete 3.0.0-rc.5 → 3.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/import.mjs +3 -3
  2. package/dist/main.js +4 -4
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +3 -3
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +4 -0
  7. package/package.json +15 -24
  8. package/src/index.ts +4 -5
  9. package/dist/ar-AE.main.js +0 -6
  10. package/dist/ar-AE.main.js.map +0 -1
  11. package/dist/ar-AE.mjs +0 -8
  12. package/dist/ar-AE.module.js +0 -8
  13. package/dist/ar-AE.module.js.map +0 -1
  14. package/dist/bg-BG.main.js +0 -6
  15. package/dist/bg-BG.main.js.map +0 -1
  16. package/dist/bg-BG.mjs +0 -8
  17. package/dist/bg-BG.module.js +0 -8
  18. package/dist/bg-BG.module.js.map +0 -1
  19. package/dist/cs-CZ.main.js +0 -6
  20. package/dist/cs-CZ.main.js.map +0 -1
  21. package/dist/cs-CZ.mjs +0 -8
  22. package/dist/cs-CZ.module.js +0 -8
  23. package/dist/cs-CZ.module.js.map +0 -1
  24. package/dist/da-DK.main.js +0 -6
  25. package/dist/da-DK.main.js.map +0 -1
  26. package/dist/da-DK.mjs +0 -8
  27. package/dist/da-DK.module.js +0 -8
  28. package/dist/da-DK.module.js.map +0 -1
  29. package/dist/de-DE.main.js +0 -6
  30. package/dist/de-DE.main.js.map +0 -1
  31. package/dist/de-DE.mjs +0 -8
  32. package/dist/de-DE.module.js +0 -8
  33. package/dist/de-DE.module.js.map +0 -1
  34. package/dist/el-GR.main.js +0 -6
  35. package/dist/el-GR.main.js.map +0 -1
  36. package/dist/el-GR.mjs +0 -8
  37. package/dist/el-GR.module.js +0 -8
  38. package/dist/el-GR.module.js.map +0 -1
  39. package/dist/en-US.main.js +0 -6
  40. package/dist/en-US.main.js.map +0 -1
  41. package/dist/en-US.mjs +0 -8
  42. package/dist/en-US.module.js +0 -8
  43. package/dist/en-US.module.js.map +0 -1
  44. package/dist/es-ES.main.js +0 -6
  45. package/dist/es-ES.main.js.map +0 -1
  46. package/dist/es-ES.mjs +0 -8
  47. package/dist/es-ES.module.js +0 -8
  48. package/dist/es-ES.module.js.map +0 -1
  49. package/dist/et-EE.main.js +0 -6
  50. package/dist/et-EE.main.js.map +0 -1
  51. package/dist/et-EE.mjs +0 -8
  52. package/dist/et-EE.module.js +0 -8
  53. package/dist/et-EE.module.js.map +0 -1
  54. package/dist/fi-FI.main.js +0 -6
  55. package/dist/fi-FI.main.js.map +0 -1
  56. package/dist/fi-FI.mjs +0 -8
  57. package/dist/fi-FI.module.js +0 -8
  58. package/dist/fi-FI.module.js.map +0 -1
  59. package/dist/fr-FR.main.js +0 -6
  60. package/dist/fr-FR.main.js.map +0 -1
  61. package/dist/fr-FR.mjs +0 -8
  62. package/dist/fr-FR.module.js +0 -8
  63. package/dist/fr-FR.module.js.map +0 -1
  64. package/dist/he-IL.main.js +0 -6
  65. package/dist/he-IL.main.js.map +0 -1
  66. package/dist/he-IL.mjs +0 -8
  67. package/dist/he-IL.module.js +0 -8
  68. package/dist/he-IL.module.js.map +0 -1
  69. package/dist/hr-HR.main.js +0 -6
  70. package/dist/hr-HR.main.js.map +0 -1
  71. package/dist/hr-HR.mjs +0 -8
  72. package/dist/hr-HR.module.js +0 -8
  73. package/dist/hr-HR.module.js.map +0 -1
  74. package/dist/hu-HU.main.js +0 -6
  75. package/dist/hu-HU.main.js.map +0 -1
  76. package/dist/hu-HU.mjs +0 -8
  77. package/dist/hu-HU.module.js +0 -8
  78. package/dist/hu-HU.module.js.map +0 -1
  79. package/dist/intlStrings.main.js +0 -108
  80. package/dist/intlStrings.main.js.map +0 -1
  81. package/dist/intlStrings.mjs +0 -110
  82. package/dist/intlStrings.module.js +0 -110
  83. package/dist/intlStrings.module.js.map +0 -1
  84. package/dist/it-IT.main.js +0 -6
  85. package/dist/it-IT.main.js.map +0 -1
  86. package/dist/it-IT.mjs +0 -8
  87. package/dist/it-IT.module.js +0 -8
  88. package/dist/it-IT.module.js.map +0 -1
  89. package/dist/ja-JP.main.js +0 -6
  90. package/dist/ja-JP.main.js.map +0 -1
  91. package/dist/ja-JP.mjs +0 -8
  92. package/dist/ja-JP.module.js +0 -8
  93. package/dist/ja-JP.module.js.map +0 -1
  94. package/dist/ko-KR.main.js +0 -6
  95. package/dist/ko-KR.main.js.map +0 -1
  96. package/dist/ko-KR.mjs +0 -8
  97. package/dist/ko-KR.module.js +0 -8
  98. package/dist/ko-KR.module.js.map +0 -1
  99. package/dist/lt-LT.main.js +0 -6
  100. package/dist/lt-LT.main.js.map +0 -1
  101. package/dist/lt-LT.mjs +0 -8
  102. package/dist/lt-LT.module.js +0 -8
  103. package/dist/lt-LT.module.js.map +0 -1
  104. package/dist/lv-LV.main.js +0 -6
  105. package/dist/lv-LV.main.js.map +0 -1
  106. package/dist/lv-LV.mjs +0 -8
  107. package/dist/lv-LV.module.js +0 -8
  108. package/dist/lv-LV.module.js.map +0 -1
  109. package/dist/nb-NO.main.js +0 -6
  110. package/dist/nb-NO.main.js.map +0 -1
  111. package/dist/nb-NO.mjs +0 -8
  112. package/dist/nb-NO.module.js +0 -8
  113. package/dist/nb-NO.module.js.map +0 -1
  114. package/dist/nl-NL.main.js +0 -6
  115. package/dist/nl-NL.main.js.map +0 -1
  116. package/dist/nl-NL.mjs +0 -8
  117. package/dist/nl-NL.module.js +0 -8
  118. package/dist/nl-NL.module.js.map +0 -1
  119. package/dist/pl-PL.main.js +0 -6
  120. package/dist/pl-PL.main.js.map +0 -1
  121. package/dist/pl-PL.mjs +0 -8
  122. package/dist/pl-PL.module.js +0 -8
  123. package/dist/pl-PL.module.js.map +0 -1
  124. package/dist/pt-BR.main.js +0 -6
  125. package/dist/pt-BR.main.js.map +0 -1
  126. package/dist/pt-BR.mjs +0 -8
  127. package/dist/pt-BR.module.js +0 -8
  128. package/dist/pt-BR.module.js.map +0 -1
  129. package/dist/pt-PT.main.js +0 -6
  130. package/dist/pt-PT.main.js.map +0 -1
  131. package/dist/pt-PT.mjs +0 -8
  132. package/dist/pt-PT.module.js +0 -8
  133. package/dist/pt-PT.module.js.map +0 -1
  134. package/dist/ro-RO.main.js +0 -6
  135. package/dist/ro-RO.main.js.map +0 -1
  136. package/dist/ro-RO.mjs +0 -8
  137. package/dist/ro-RO.module.js +0 -8
  138. package/dist/ro-RO.module.js.map +0 -1
  139. package/dist/ru-RU.main.js +0 -6
  140. package/dist/ru-RU.main.js.map +0 -1
  141. package/dist/ru-RU.mjs +0 -8
  142. package/dist/ru-RU.module.js +0 -8
  143. package/dist/ru-RU.module.js.map +0 -1
  144. package/dist/sk-SK.main.js +0 -6
  145. package/dist/sk-SK.main.js.map +0 -1
  146. package/dist/sk-SK.mjs +0 -8
  147. package/dist/sk-SK.module.js +0 -8
  148. package/dist/sk-SK.module.js.map +0 -1
  149. package/dist/sl-SI.main.js +0 -6
  150. package/dist/sl-SI.main.js.map +0 -1
  151. package/dist/sl-SI.mjs +0 -8
  152. package/dist/sl-SI.module.js +0 -8
  153. package/dist/sl-SI.module.js.map +0 -1
  154. package/dist/sr-SP.main.js +0 -6
  155. package/dist/sr-SP.main.js.map +0 -1
  156. package/dist/sr-SP.mjs +0 -8
  157. package/dist/sr-SP.module.js +0 -8
  158. package/dist/sr-SP.module.js.map +0 -1
  159. package/dist/sv-SE.main.js +0 -6
  160. package/dist/sv-SE.main.js.map +0 -1
  161. package/dist/sv-SE.mjs +0 -8
  162. package/dist/sv-SE.module.js +0 -8
  163. package/dist/sv-SE.module.js.map +0 -1
  164. package/dist/tr-TR.main.js +0 -6
  165. package/dist/tr-TR.main.js.map +0 -1
  166. package/dist/tr-TR.mjs +0 -8
  167. package/dist/tr-TR.module.js +0 -8
  168. package/dist/tr-TR.module.js.map +0 -1
  169. package/dist/types.d.ts +0 -97
  170. package/dist/types.d.ts.map +0 -1
  171. package/dist/uk-UA.main.js +0 -6
  172. package/dist/uk-UA.main.js.map +0 -1
  173. package/dist/uk-UA.mjs +0 -8
  174. package/dist/uk-UA.module.js +0 -8
  175. package/dist/uk-UA.module.js.map +0 -1
  176. package/dist/useAutocomplete.main.js +0 -318
  177. package/dist/useAutocomplete.main.js.map +0 -1
  178. package/dist/useAutocomplete.mjs +0 -313
  179. package/dist/useAutocomplete.module.js +0 -313
  180. package/dist/useAutocomplete.module.js.map +0 -1
  181. package/dist/useSearchAutocomplete.main.js +0 -73
  182. package/dist/useSearchAutocomplete.main.js.map +0 -1
  183. package/dist/useSearchAutocomplete.mjs +0 -68
  184. package/dist/useSearchAutocomplete.module.js +0 -68
  185. package/dist/useSearchAutocomplete.module.js.map +0 -1
  186. package/dist/zh-CN.main.js +0 -6
  187. package/dist/zh-CN.main.js.map +0 -1
  188. package/dist/zh-CN.mjs +0 -8
  189. package/dist/zh-CN.module.js +0 -8
  190. package/dist/zh-CN.module.js.map +0 -1
  191. package/dist/zh-TW.main.js +0 -6
  192. package/dist/zh-TW.main.js.map +0 -1
  193. package/dist/zh-TW.mjs +0 -8
  194. package/dist/zh-TW.module.js +0 -8
  195. package/dist/zh-TW.module.js.map +0 -1
  196. package/src/useAutocomplete.ts +0 -437
  197. package/src/useSearchAutocomplete.ts +0 -133
@@ -1,318 +0,0 @@
1
- var $fbc7b37667f52272$exports = require("./intlStrings.main.js");
2
- var $4yz2I$reactariautils = require("@react-aria/utils");
3
- var $4yz2I$reactariafocus = require("@react-aria/focus");
4
- var $4yz2I$reactariainteractions = require("@react-aria/interactions");
5
- var $4yz2I$react = require("react");
6
- var $4yz2I$reactariai18n = require("@react-aria/i18n");
7
-
8
-
9
- function $parcel$interopDefault(a) {
10
- return a && a.__esModule ? a.default : a;
11
- }
12
-
13
- function $parcel$export(e, n, v, s) {
14
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
- }
16
-
17
- $parcel$export(module.exports, "useAutocomplete", () => $d43aec1bf2be84e8$export$1e40b3ca02d92d21);
18
- /*
19
- * Copyright 2024 Adobe. All rights reserved.
20
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License. You may obtain a copy
22
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software distributed under
25
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
26
- * OF ANY KIND, either express or implied. See the License for the specific language
27
- * governing permissions and limitations under the License.
28
- */
29
-
30
-
31
-
32
-
33
-
34
- function $d43aec1bf2be84e8$export$1e40b3ca02d92d21(props, state) {
35
- let { inputRef: inputRef, collectionRef: collectionRef, filter: filter, disableAutoFocusFirst: disableAutoFocusFirst = false, disableVirtualFocus: disableVirtualFocus = false } = props;
36
- let collectionId = (0, $4yz2I$reactariautils.useId)();
37
- let timeout = (0, $4yz2I$react.useRef)(undefined);
38
- let delayNextActiveDescendant = (0, $4yz2I$react.useRef)(false);
39
- let queuedActiveDescendant = (0, $4yz2I$react.useRef)(null);
40
- // For mobile screen readers, we don't want virtual focus, instead opting to disable FocusScope's restoreFocus and manually
41
- // moving focus back to the subtriggers
42
- let isMobileScreenReader = (0, $4yz2I$reactariainteractions.getInteractionModality)() === 'virtual' && ((0, $4yz2I$reactariautils.isIOS)() || (0, $4yz2I$reactariautils.isAndroid)());
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);
47
- (0, $4yz2I$react.useEffect)(()=>{
48
- return ()=>clearTimeout(timeout.current);
49
- }, []);
50
- let updateActiveDescendantEvent = (0, $4yz2I$reactariautils.useEffectEvent)((e)=>{
51
- // Ensure input is focused if the user clicks on the collection directly.
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();
54
- let target = e.target;
55
- if (e.isTrusted || !target || queuedActiveDescendant.current === target.id) return;
56
- clearTimeout(timeout.current);
57
- if (target !== collectionRef.current) {
58
- if (delayNextActiveDescendant.current) {
59
- queuedActiveDescendant.current = target.id;
60
- timeout.current = setTimeout(()=>{
61
- state.setFocusedNodeId(target.id);
62
- }, 500);
63
- } else {
64
- queuedActiveDescendant.current = target.id;
65
- state.setFocusedNodeId(target.id);
66
- }
67
- } else if (queuedActiveDescendant.current && !document.getElementById(queuedActiveDescendant.current)) {
68
- // If we recieve a focus event refocusing the collection, either we have newly refocused the input and are waiting for the
69
- // wrapped collection to refocus the previously focused node if any OR
70
- // 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.
71
- // In this case we want to clear tracked item if any and clear active descendant
72
- queuedActiveDescendant.current = null;
73
- state.setFocusedNodeId(null);
74
- }
75
- delayNextActiveDescendant.current = false;
76
- });
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
- };
95
- }, [
96
- collectionNode
97
- ]);
98
- // Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection
99
- let mergedCollectionRef = (0, $4yz2I$reactariautils.useObjectRef)((0, $4yz2I$react.useMemo)(()=>(0, $4yz2I$reactariautils.mergeRefs)(collectionRef, callbackRef), [
100
- collectionRef,
101
- callbackRef
102
- ]));
103
- let focusFirstItem = (0, $4yz2I$react.useCallback)(()=>{
104
- var _collectionRef_current;
105
- delayNextActiveDescendant.current = true;
106
- (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new CustomEvent((0, $4yz2I$reactariautils.FOCUS_EVENT), {
107
- cancelable: true,
108
- bubbles: true,
109
- detail: {
110
- focusStrategy: 'first'
111
- }
112
- }));
113
- }, [
114
- collectionRef
115
- ]);
116
- let clearVirtualFocus = (0, $4yz2I$react.useCallback)((clearFocusKey)=>{
117
- var _collectionRef_current;
118
- (0, $4yz2I$reactariafocus.moveVirtualFocus)((0, $4yz2I$reactariautils.getActiveElement)());
119
- queuedActiveDescendant.current = null;
120
- state.setFocusedNodeId(null);
121
- let clearFocusEvent = new CustomEvent((0, $4yz2I$reactariautils.CLEAR_FOCUS_EVENT), {
122
- cancelable: true,
123
- bubbles: true,
124
- detail: {
125
- clearFocusKey: clearFocusKey
126
- }
127
- });
128
- clearTimeout(timeout.current);
129
- delayNextActiveDescendant.current = false;
130
- (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(clearFocusEvent);
131
- }, [
132
- collectionRef,
133
- state
134
- ]);
135
- let lastInputType = (0, $4yz2I$react.useRef)('');
136
- (0, $4yz2I$reactariautils.useEvent)(inputRef, 'input', (e)=>{
137
- let { inputType: inputType } = e;
138
- lastInputType.current = inputType;
139
- });
140
- let onChange = (value)=>{
141
- // Tell wrapped collection to focus the first element in the list when typing forward and to clear focused key when modifying the text via
142
- // copy paste/backspacing/undo/redo for screen reader announcements
143
- if (lastInputType.current === 'insertText' && !disableAutoFocusFirst) focusFirstItem();
144
- else if (lastInputType.current && (lastInputType.current.includes('insert') || lastInputType.current.includes('delete') || lastInputType.current.includes('history'))) {
145
- clearVirtualFocus(true);
146
- // If onChange was triggered before the timeout actually updated the activedescendant, we need to fire
147
- // our own dispatchVirtualFocus so focusVisible gets reapplied on the input
148
- if ((0, $4yz2I$reactariafocus.getVirtuallyFocusedElement)(document) === inputRef.current) (0, $4yz2I$reactariafocus.dispatchVirtualFocus)(inputRef.current, null);
149
- }
150
- state.setInputValue(value);
151
- };
152
- let keyDownTarget = (0, $4yz2I$react.useRef)(null);
153
- // For textfield specific keydown operations
154
- let onKeyDown = (e)=>{
155
- keyDownTarget.current = e.target;
156
- if (e.nativeEvent.isComposing) return;
157
- let focusedNodeId = queuedActiveDescendant.current;
158
- switch(e.key){
159
- case 'a':
160
- if ((0, $4yz2I$reactariautils.isCtrlKeyPressed)(e)) return;
161
- break;
162
- case 'Escape':
163
- // Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and
164
- // close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check
165
- // for isPropagationStopped
166
- if (e.isDefaultPrevented()) return;
167
- break;
168
- case ' ':
169
- // Space shouldn't trigger onAction so early return.
170
- return;
171
- case 'Tab':
172
- // 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)
173
- // We want FocusScope to handle Tab if one exists (aka sub dialog), so special casepropogate
174
- if ('continuePropagation' in e) e.continuePropagation();
175
- return;
176
- case 'Home':
177
- case 'End':
178
- case 'PageDown':
179
- case 'PageUp':
180
- case 'ArrowUp':
181
- case 'ArrowDown':
182
- {
183
- var _collectionRef_current;
184
- if ((e.key === 'Home' || e.key === 'End') && focusedNodeId == null && e.shiftKey) return;
185
- // Prevent these keys from moving the text cursor in the input
186
- e.preventDefault();
187
- // Move virtual focus into the wrapped collection
188
- let focusCollection = new CustomEvent((0, $4yz2I$reactariautils.FOCUS_EVENT), {
189
- cancelable: true,
190
- bubbles: true
191
- });
192
- (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(focusCollection);
193
- break;
194
- }
195
- }
196
- // Emulate the keyboard events that happen in the input field in the wrapped collection. This is for triggering things like onAction via Enter
197
- // 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
198
- // like ESC, the dispatched event below will bubble out of the collection and be stopped if handled by useSelectableCollection, otherwise will bubble
199
- // as expected
200
- if (!e.isPropagationStopped()) e.stopPropagation();
201
- let shouldPerformDefaultAction = true;
202
- if (collectionRef.current !== null) {
203
- var _collectionRef_current1;
204
- if (focusedNodeId == null) shouldPerformDefaultAction = ((_collectionRef_current1 = collectionRef.current) === null || _collectionRef_current1 === void 0 ? void 0 : _collectionRef_current1.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent))) || false;
205
- else {
206
- let item = document.getElementById(focusedNodeId);
207
- if (item) shouldPerformDefaultAction = (item === null || item === void 0 ? void 0 : item.dispatchEvent(new KeyboardEvent(e.nativeEvent.type, e.nativeEvent))) || false;
208
- }
209
- }
210
- if (shouldPerformDefaultAction) switch(e.key){
211
- case 'ArrowLeft':
212
- case 'ArrowRight':
213
- // Clear the activedescendant so NVDA announcements aren't interrupted but retain the focused key in the collection so the
214
- // user's keyboard navigation restarts from where they left off
215
- clearVirtualFocus();
216
- break;
217
- case 'Enter':
218
- // Trigger click action on item when Enter key was pressed.
219
- if (focusedNodeId != null) {
220
- let item = document.getElementById(focusedNodeId);
221
- item === null || item === void 0 ? void 0 : item.dispatchEvent(new PointerEvent('click', e.nativeEvent));
222
- }
223
- break;
224
- }
225
- else // TODO: check if we can do this, want to stop textArea from using its default Enter behavior so items are properly triggered
226
- e.preventDefault();
227
- };
228
- let onKeyUpCapture = (0, $4yz2I$reactariautils.useEffectEvent)((e)=>{
229
- // Dispatch simulated key up events for things like triggering links in listbox
230
- // Make sure to stop the propagation of the input keyup event so that the simulated keyup/down pair
231
- // is detected by usePress instead of the original keyup originating from the input
232
- if (e.target === keyDownTarget.current) {
233
- var _collectionRef_current;
234
- e.stopImmediatePropagation();
235
- let focusedNodeId = queuedActiveDescendant.current;
236
- if (focusedNodeId == null) (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dispatchEvent(new KeyboardEvent(e.type, e));
237
- else {
238
- let item = document.getElementById(focusedNodeId);
239
- item === null || item === void 0 ? void 0 : item.dispatchEvent(new KeyboardEvent(e.type, e));
240
- }
241
- }
242
- });
243
- (0, $4yz2I$react.useEffect)(()=>{
244
- document.addEventListener('keyup', onKeyUpCapture, true);
245
- return ()=>{
246
- document.removeEventListener('keyup', onKeyUpCapture, true);
247
- };
248
- }, []);
249
- let stringFormatter = (0, $4yz2I$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($fbc7b37667f52272$exports))), '@react-aria/autocomplete');
250
- let collectionProps = (0, $4yz2I$reactariautils.useLabels)({
251
- id: collectionId,
252
- 'aria-label': stringFormatter.format('collectionLabel')
253
- });
254
- let filterFn = (0, $4yz2I$react.useCallback)((nodeTextValue, node)=>{
255
- if (filter) return filter(nodeTextValue, state.inputValue, node);
256
- return true;
257
- }, [
258
- state.inputValue,
259
- filter
260
- ]);
261
- // Be sure to clear/restore the virtual + collection focus when blurring/refocusing the field so we only show the
262
- // focus ring on the virtually focused collection when are actually interacting with the Autocomplete
263
- let onBlur = (e)=>{
264
- if (!e.isTrusted) return;
265
- let lastFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;
266
- if (lastFocusedNode) (0, $4yz2I$reactariafocus.dispatchVirtualBlur)(lastFocusedNode, e.relatedTarget);
267
- };
268
- let onFocus = (e)=>{
269
- if (!e.isTrusted) return;
270
- let curFocusedNode = queuedActiveDescendant.current ? document.getElementById(queuedActiveDescendant.current) : null;
271
- if (curFocusedNode) {
272
- let target = e.target;
273
- queueMicrotask(()=>{
274
- // instead of focusing the last focused node, just focus the collection instead and have the collection handle what item to focus via useSelectableCollection/Item
275
- (0, $4yz2I$reactariafocus.dispatchVirtualBlur)(target, collectionRef.current);
276
- (0, $4yz2I$reactariafocus.dispatchVirtualFocus)(collectionRef.current, target);
277
- });
278
- }
279
- };
280
- // Only apply the autocomplete specific behaviors if the collection component wrapped by it is actually
281
- // being filtered/allows filtering by the Autocomplete.
282
- let inputProps = {
283
- value: state.inputValue,
284
- onChange: onChange
285
- };
286
- var _state_focusedNodeId;
287
- let virtualFocusProps = {
288
- onKeyDown: onKeyDown,
289
- 'aria-activedescendant': (_state_focusedNodeId = state.focusedNodeId) !== null && _state_focusedNodeId !== void 0 ? _state_focusedNodeId : undefined,
290
- onBlur: onBlur,
291
- onFocus: onFocus
292
- };
293
- if (hasCollection) inputProps = {
294
- ...inputProps,
295
- ...shouldUseVirtualFocus && virtualFocusProps,
296
- enterKeyHint: 'go',
297
- 'aria-controls': collectionId,
298
- // TODO: readd proper logic for completionMode = complete (aria-autocomplete: both)
299
- 'aria-autocomplete': 'list',
300
- // This disable's iOS's autocorrect suggestions, since the autocomplete provides its own suggestions.
301
- autoCorrect: 'off',
302
- // This disable's the macOS Safari spell check auto corrections.
303
- spellCheck: 'false',
304
- autoComplete: 'off'
305
- };
306
- return {
307
- inputProps: inputProps,
308
- collectionProps: (0, $4yz2I$reactariautils.mergeProps)(collectionProps, {
309
- shouldUseVirtualFocus: shouldUseVirtualFocus,
310
- disallowTypeAhead: shouldUseVirtualFocus
311
- }),
312
- collectionRef: mergedCollectionRef,
313
- filter: filter != null ? filterFn : undefined
314
- };
315
- }
316
-
317
-
318
- //# sourceMappingURL=useAutocomplete.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;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ACA,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"}