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