@react-aria/select 3.14.4-nightly.4555 → 3.14.4-nightly.4560
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/HiddenSelect.main.js +129 -0
- package/dist/HiddenSelect.main.js.map +1 -0
- package/dist/HiddenSelect.mjs +119 -0
- package/dist/HiddenSelect.module.js +119 -0
- package/dist/HiddenSelect.module.js.map +1 -0
- package/dist/import.mjs +2 -264
- package/dist/main.js +5 -271
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -264
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/useSelect.main.js +163 -0
- package/dist/useSelect.main.js.map +1 -0
- package/dist/useSelect.mjs +157 -0
- package/dist/useSelect.module.js +157 -0
- package/dist/useSelect.module.js.map +1 -0
- package/package.json +15 -15
package/dist/module.js
CHANGED
|
@@ -1,169 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {ListKeyboardDelegate as $thkiX$ListKeyboardDelegate, useTypeSelect as $thkiX$useTypeSelect} from "@react-aria/selection";
|
|
4
|
-
import {setInteractionModality as $thkiX$setInteractionModality, useInteractionModality as $thkiX$useInteractionModality} from "@react-aria/interactions";
|
|
5
|
-
import {useCollator as $thkiX$useCollator} from "@react-aria/i18n";
|
|
6
|
-
import {useField as $thkiX$useField} from "@react-aria/label";
|
|
7
|
-
import {useMenuTrigger as $thkiX$useMenuTrigger} from "@react-aria/menu";
|
|
8
|
-
import {useFormValidation as $thkiX$useFormValidation} from "@react-aria/form";
|
|
9
|
-
import {useVisuallyHidden as $thkiX$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
10
|
-
|
|
11
|
-
/*
|
|
12
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
-
* governing permissions and limitations under the License.
|
|
21
|
-
*/ /*
|
|
22
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
23
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
24
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
25
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
26
|
-
*
|
|
27
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
28
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
29
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
30
|
-
* governing permissions and limitations under the License.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const $58aed456727eb0f3$export$703601b7e90536f8 = new WeakMap();
|
|
39
|
-
function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
40
|
-
let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
41
|
-
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
42
|
-
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
43
|
-
let collator = (0, $thkiX$useCollator)({
|
|
44
|
-
usage: "search",
|
|
45
|
-
sensitivity: "base"
|
|
46
|
-
});
|
|
47
|
-
let delegate = (0, $thkiX$useMemo)(()=>keyboardDelegate || new (0, $thkiX$ListKeyboardDelegate)(state.collection, state.disabledKeys, null, collator), [
|
|
48
|
-
keyboardDelegate,
|
|
49
|
-
state.collection,
|
|
50
|
-
state.disabledKeys,
|
|
51
|
-
collator
|
|
52
|
-
]);
|
|
53
|
-
let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $thkiX$useMenuTrigger)({
|
|
54
|
-
isDisabled: isDisabled,
|
|
55
|
-
type: "listbox"
|
|
56
|
-
}, state, ref);
|
|
57
|
-
let onKeyDown = (e)=>{
|
|
58
|
-
switch(e.key){
|
|
59
|
-
case "ArrowLeft":
|
|
60
|
-
{
|
|
61
|
-
// prevent scrolling containers
|
|
62
|
-
e.preventDefault();
|
|
63
|
-
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
64
|
-
if (key) state.setSelectedKey(key);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
case "ArrowRight":
|
|
68
|
-
{
|
|
69
|
-
// prevent scrolling containers
|
|
70
|
-
e.preventDefault();
|
|
71
|
-
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
72
|
-
if (key) state.setSelectedKey(key);
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
let { typeSelectProps: typeSelectProps } = (0, $thkiX$useTypeSelect)({
|
|
78
|
-
keyboardDelegate: delegate,
|
|
79
|
-
selectionManager: state.selectionManager,
|
|
80
|
-
onTypeSelect (key) {
|
|
81
|
-
state.setSelectedKey(key);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
85
|
-
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $thkiX$useField)({
|
|
86
|
-
...props,
|
|
87
|
-
labelElementType: "span",
|
|
88
|
-
isInvalid: isInvalid,
|
|
89
|
-
errorMessage: props.errorMessage || validationErrors
|
|
90
|
-
});
|
|
91
|
-
typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;
|
|
92
|
-
delete typeSelectProps.onKeyDownCapture;
|
|
93
|
-
let domProps = (0, $thkiX$filterDOMProps)(props, {
|
|
94
|
-
labelable: true
|
|
95
|
-
});
|
|
96
|
-
let triggerProps = (0, $thkiX$mergeProps)(typeSelectProps, menuTriggerProps, fieldProps);
|
|
97
|
-
let valueId = (0, $thkiX$useId)();
|
|
98
|
-
$58aed456727eb0f3$export$703601b7e90536f8.set(state, {
|
|
99
|
-
isDisabled: isDisabled,
|
|
100
|
-
isRequired: isRequired,
|
|
101
|
-
name: name,
|
|
102
|
-
validationBehavior: validationBehavior
|
|
103
|
-
});
|
|
104
|
-
return {
|
|
105
|
-
labelProps: {
|
|
106
|
-
...labelProps,
|
|
107
|
-
onClick: ()=>{
|
|
108
|
-
if (!props.isDisabled) {
|
|
109
|
-
ref.current.focus();
|
|
110
|
-
// Show the focus ring so the user knows where focus went
|
|
111
|
-
(0, $thkiX$setInteractionModality)("keyboard");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
triggerProps: (0, $thkiX$mergeProps)(domProps, {
|
|
116
|
-
...triggerProps,
|
|
117
|
-
isDisabled: isDisabled,
|
|
118
|
-
onKeyDown: (0, $thkiX$chain)(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),
|
|
119
|
-
onKeyUp: props.onKeyUp,
|
|
120
|
-
"aria-labelledby": [
|
|
121
|
-
valueId,
|
|
122
|
-
triggerProps["aria-labelledby"],
|
|
123
|
-
triggerProps["aria-label"] && !triggerProps["aria-labelledby"] ? triggerProps.id : null
|
|
124
|
-
].filter(Boolean).join(" "),
|
|
125
|
-
onFocus (e) {
|
|
126
|
-
if (state.isFocused) return;
|
|
127
|
-
if (props.onFocus) props.onFocus(e);
|
|
128
|
-
if (props.onFocusChange) props.onFocusChange(true);
|
|
129
|
-
state.setFocused(true);
|
|
130
|
-
},
|
|
131
|
-
onBlur (e) {
|
|
132
|
-
if (state.isOpen) return;
|
|
133
|
-
if (props.onBlur) props.onBlur(e);
|
|
134
|
-
if (props.onFocusChange) props.onFocusChange(false);
|
|
135
|
-
state.setFocused(false);
|
|
136
|
-
}
|
|
137
|
-
}),
|
|
138
|
-
valueProps: {
|
|
139
|
-
id: valueId
|
|
140
|
-
},
|
|
141
|
-
menuProps: {
|
|
142
|
-
...menuProps,
|
|
143
|
-
autoFocus: state.focusStrategy || true,
|
|
144
|
-
shouldSelectOnPressUp: true,
|
|
145
|
-
shouldFocusOnHover: true,
|
|
146
|
-
disallowEmptySelection: true,
|
|
147
|
-
linkBehavior: "selection",
|
|
148
|
-
onBlur: (e)=>{
|
|
149
|
-
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
150
|
-
if (props.onBlur) props.onBlur(e);
|
|
151
|
-
if (props.onFocusChange) props.onFocusChange(false);
|
|
152
|
-
state.setFocused(false);
|
|
153
|
-
},
|
|
154
|
-
"aria-labelledby": [
|
|
155
|
-
fieldProps["aria-labelledby"],
|
|
156
|
-
triggerProps["aria-label"] && !fieldProps["aria-labelledby"] ? triggerProps.id : null
|
|
157
|
-
].filter(Boolean).join(" ")
|
|
158
|
-
},
|
|
159
|
-
descriptionProps: descriptionProps,
|
|
160
|
-
errorMessageProps: errorMessageProps,
|
|
161
|
-
isInvalid: isInvalid,
|
|
162
|
-
validationErrors: validationErrors,
|
|
163
|
-
validationDetails: validationDetails
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
1
|
+
import {useSelect as $58aed456727eb0f3$export$e64b2f635402ca43} from "./useSelect.module.js";
|
|
2
|
+
import {HiddenSelect as $bdd25dc72710631f$export$cbd84cdb2e668835, useHiddenSelect as $bdd25dc72710631f$export$f809e80f58e251d1} from "./HiddenSelect.module.js";
|
|
167
3
|
|
|
168
4
|
/*
|
|
169
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -179,103 +15,5 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
179
15
|
|
|
180
16
|
|
|
181
17
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
185
|
-
let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
|
|
186
|
-
let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
|
|
187
|
-
let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
|
|
188
|
-
let modality = (0, $thkiX$useInteractionModality)();
|
|
189
|
-
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $thkiX$useVisuallyHidden)();
|
|
190
|
-
(0, $thkiX$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
|
|
191
|
-
(0, $thkiX$useFormValidation)({
|
|
192
|
-
validationBehavior: validationBehavior,
|
|
193
|
-
focus: ()=>triggerRef.current.focus()
|
|
194
|
-
}, state, props.selectRef);
|
|
195
|
-
var _state_selectedKey;
|
|
196
|
-
// In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
|
|
197
|
-
// In Firefox, there must be a <label> to identify the <select> whereas other browsers
|
|
198
|
-
// seem to identify it just by surrounding text.
|
|
199
|
-
// The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
|
|
200
|
-
// 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
|
|
201
|
-
// non tabbable with tabIndex={-1}.
|
|
202
|
-
//
|
|
203
|
-
// In mobile browsers, there are next/previous buttons above the software keyboard for navigating
|
|
204
|
-
// between fields in a form. These only support native form inputs that are tabbable. In order to
|
|
205
|
-
// support those, an additional hidden input is used to marshall focus to the button. It is tabbable
|
|
206
|
-
// except when the button is focused, so that shift tab works properly to go to the actual previous
|
|
207
|
-
// input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
|
|
208
|
-
// the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
|
|
209
|
-
// prevent Safari from zooming in on the input when it is focused.
|
|
210
|
-
//
|
|
211
|
-
// If the current interaction modality is null, then the user hasn't interacted with the page yet.
|
|
212
|
-
// In this case, we set the tabIndex to -1 on the input element so that automated accessibility
|
|
213
|
-
// checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
|
|
214
|
-
return {
|
|
215
|
-
containerProps: {
|
|
216
|
-
...visuallyHiddenProps,
|
|
217
|
-
"aria-hidden": true,
|
|
218
|
-
["data-hidden-select-ignore"]: true,
|
|
219
|
-
["data-a11y-ignore"]: "aria-hidden-focus"
|
|
220
|
-
},
|
|
221
|
-
inputProps: {
|
|
222
|
-
type: "text",
|
|
223
|
-
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
|
|
224
|
-
style: {
|
|
225
|
-
fontSize: 16
|
|
226
|
-
},
|
|
227
|
-
onFocus: ()=>triggerRef.current.focus(),
|
|
228
|
-
disabled: isDisabled
|
|
229
|
-
},
|
|
230
|
-
selectProps: {
|
|
231
|
-
tabIndex: -1,
|
|
232
|
-
autoComplete: autoComplete,
|
|
233
|
-
disabled: isDisabled,
|
|
234
|
-
required: validationBehavior === "native" && isRequired,
|
|
235
|
-
name: name,
|
|
236
|
-
value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : "",
|
|
237
|
-
onChange: (e)=>state.setSelectedKey(e.target.value)
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
|
|
242
|
-
let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
|
|
243
|
-
let selectRef = (0, $thkiX$useRef)(null);
|
|
244
|
-
let { containerProps: containerProps, inputProps: inputProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
|
|
245
|
-
...props,
|
|
246
|
-
selectRef: selectRef
|
|
247
|
-
}, state, triggerRef);
|
|
248
|
-
var _state_selectedKey;
|
|
249
|
-
// If used in a <form>, use a hidden input so the value can be submitted to a server.
|
|
250
|
-
// If the collection isn't too big, use a hidden <select> element for this so that browser
|
|
251
|
-
// autofill will work. Otherwise, use an <input type="hidden">.
|
|
252
|
-
if (state.collection.size <= 300) return /*#__PURE__*/ (0, $thkiX$react).createElement("div", {
|
|
253
|
-
...containerProps,
|
|
254
|
-
"data-testid": "hidden-select-container"
|
|
255
|
-
}, /*#__PURE__*/ (0, $thkiX$react).createElement("input", inputProps), /*#__PURE__*/ (0, $thkiX$react).createElement("label", null, label, /*#__PURE__*/ (0, $thkiX$react).createElement("select", {
|
|
256
|
-
...selectProps,
|
|
257
|
-
ref: selectRef
|
|
258
|
-
}, /*#__PURE__*/ (0, $thkiX$react).createElement("option", null), [
|
|
259
|
-
...state.collection.getKeys()
|
|
260
|
-
].map((key)=>{
|
|
261
|
-
let item = state.collection.getItem(key);
|
|
262
|
-
if (item.type === "item") return /*#__PURE__*/ (0, $thkiX$react).createElement("option", {
|
|
263
|
-
key: item.key,
|
|
264
|
-
value: item.key
|
|
265
|
-
}, item.textValue);
|
|
266
|
-
}))));
|
|
267
|
-
else if (name) return /*#__PURE__*/ (0, $thkiX$react).createElement("input", {
|
|
268
|
-
type: "hidden",
|
|
269
|
-
autoComplete: selectProps.autoComplete,
|
|
270
|
-
name: name,
|
|
271
|
-
disabled: isDisabled,
|
|
272
|
-
value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ""
|
|
273
|
-
});
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
18
|
export {$58aed456727eb0f3$export$e64b2f635402ca43 as useSelect, $bdd25dc72710631f$export$f809e80f58e251d1 as useHiddenSelect, $bdd25dc72710631f$export$cbd84cdb2e668835 as HiddenSelect};
|
|
281
19
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;C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I,IAAI,KAC3B,qBACE,gCAAC;QAAK,GAAG,cAAc;QAAE,eAAY;qBACnC,gCAAC,SAAU,2BACX,gCAAC,eACE,qBACD,gCAAC;QAAQ,GAAG,WAAW;QAAE,KAAK;qBAC5B,gCAAC,iBACA;WAAI,MAAM,UAAU,CAAC,OAAO;KAAG,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC;QACpC,IAAI,KAAK,IAAI,KAAK,QAChB,qBACE,gCAAC;YACC,KAAK,KAAK,GAAG;YACb,OAAO,KAAK,GAAG;WACd,KAAK,SAAS;IAIvB;SAKH,IAAI,MACT,qBACE,gCAAC;QACC,MAAK;QACL,cAAc,YAAY,YAAY;QACtC,MAAM;QACN,UAAU;QACV,OAAO,CAAA,qBAAA,MAAM,WAAW,cAAjB,gCAAA,qBAAqB;;IAIlC,OAAO;AACT;","sources":["packages/@react-aria/select/src/index.ts","packages/@react-aria/select/src/useSelect.ts","packages/@react-aria/select/src/HiddenSelect.tsx"],"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 */\nexport {useSelect} from './useSelect';\nexport {useHiddenSelect, HiddenSelect} from './HiddenSelect';\nexport type {AriaSelectOptions, SelectAria} from './useSelect';\nexport type {AriaHiddenSelectProps, HiddenSelectProps} from './HiddenSelect';\nexport type {AriaSelectProps} from '@react-types/select';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaListBoxOptions} from '@react-aria/listbox';\nimport {AriaSelectProps} from '@react-types/select';\nimport {chain, filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, KeyboardDelegate, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, RefObject, useMemo} from 'react';\nimport {ListKeyboardDelegate, useTypeSelect} from '@react-aria/selection';\nimport {SelectState} from '@react-stately/select';\nimport {setInteractionModality} from '@react-aria/interactions';\nimport {useCollator} from '@react-aria/i18n';\nimport {useField} from '@react-aria/label';\nimport {useMenuTrigger} from '@react-aria/menu';\n\nexport interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\nexport interface SelectAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n\n /** Props for the popup trigger element. */\n triggerProps: AriaButtonProps,\n\n /** Props for the element representing the selected value. */\n valueProps: DOMAttributes,\n\n /** Props for the popup. */\n menuProps: AriaListBoxOptions<T>,\n\n /** Props for the select's description element, if any. */\n descriptionProps: DOMAttributes,\n\n /** Props for the select's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\ninterface SelectData {\n isDisabled?: boolean,\n isRequired?: boolean,\n name?: string,\n validationBehavior?: 'aria' | 'native'\n}\n\nexport const selectData = new WeakMap<SelectState<any>, SelectData>();\n\n/**\n * Provides the behavior and accessibility implementation for a select component.\n * A select displays a collapsible list of options and allows a user to select one of them.\n * @param props - Props for the select.\n * @param state - State for the select, as returned by `useListState`.\n */\nexport function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<FocusableElement>): SelectAria<T> {\n let {\n keyboardDelegate,\n isDisabled,\n isRequired,\n name,\n validationBehavior = 'aria'\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(state.collection, state.disabledKeys, null, collator), [keyboardDelegate, state.collection, state.disabledKeys, collator]);\n\n let {menuTriggerProps, menuProps} = useMenuTrigger<T>(\n {\n isDisabled,\n type: 'listbox'\n },\n state,\n ref\n );\n\n let onKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowLeft': {\n // prevent scrolling containers\n e.preventDefault();\n\n let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();\n if (key) {\n state.setSelectedKey(key);\n }\n break;\n }\n case 'ArrowRight': {\n // prevent scrolling containers\n e.preventDefault();\n\n let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();\n if (key) {\n state.setSelectedKey(key);\n }\n break;\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: state.selectionManager,\n onTypeSelect(key) {\n state.setSelectedKey(key);\n }\n });\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;\n delete typeSelectProps.onKeyDownCapture;\n\n let domProps = filterDOMProps(props, {labelable: true});\n let triggerProps = mergeProps(typeSelectProps, menuTriggerProps, fieldProps);\n\n let valueId = useId();\n\n selectData.set(state, {\n isDisabled,\n isRequired,\n name,\n validationBehavior\n });\n\n return {\n labelProps: {\n ...labelProps,\n onClick: () => {\n if (!props.isDisabled) {\n ref.current.focus();\n\n // Show the focus ring so the user knows where focus went\n setInteractionModality('keyboard');\n }\n }\n },\n triggerProps: mergeProps(domProps, {\n ...triggerProps,\n isDisabled,\n onKeyDown: chain(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),\n onKeyUp: props.onKeyUp,\n 'aria-labelledby': [\n valueId,\n triggerProps['aria-labelledby'],\n triggerProps['aria-label'] && !triggerProps['aria-labelledby'] ? triggerProps.id : null\n ].filter(Boolean).join(' '),\n onFocus(e: FocusEvent) {\n if (state.isFocused) {\n return;\n }\n\n if (props.onFocus) {\n props.onFocus(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(true);\n }\n\n state.setFocused(true);\n },\n onBlur(e: FocusEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n }\n }),\n valueProps: {\n id: valueId\n },\n menuProps: {\n ...menuProps,\n autoFocus: state.focusStrategy || true,\n shouldSelectOnPressUp: true,\n shouldFocusOnHover: true,\n disallowEmptySelection: true,\n linkBehavior: 'selection',\n onBlur: (e) => {\n if (e.currentTarget.contains(e.relatedTarget as Node)) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n 'aria-labelledby': [\n fieldProps['aria-labelledby'],\n triggerProps['aria-label'] && !fieldProps['aria-labelledby'] ? triggerProps.id : null\n ].filter(Boolean).join(' ')\n },\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement} from '@react-types/shared';\nimport React, {ReactNode, RefObject, useRef} from 'react';\nimport {selectData} from './useSelect';\nimport {SelectState} from '@react-stately/select';\nimport {useFormReset} from '@react-aria/utils';\nimport {useFormValidation} from '@react-aria/form';\nimport {useInteractionModality} from '@react-aria/interactions';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaHiddenSelectProps {\n /**\n * Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).\n */\n autoComplete?: string,\n\n /** The text label for the select. */\n label?: ReactNode,\n\n /** HTML form input name. */\n name?: string,\n\n /** Sets the disabled state of the select and input. */\n isDisabled?: boolean\n}\n\nexport interface HiddenSelectProps<T> extends AriaHiddenSelectProps {\n /** State for the select. */\n state: SelectState<T>,\n\n /** A ref to the trigger element. */\n triggerRef: RefObject<FocusableElement>\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n /** A ref to the hidden `<select>` element. */\n selectRef?: RefObject<HTMLSelectElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a hidden `<select>` element, which\n * can be used in combination with `useSelect` to support browser form autofill, mobile form\n * navigation, and native HTML form submission.\n */\nexport function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: SelectState<T>, triggerRef: RefObject<FocusableElement>) {\n let data = selectData.get(state) || {};\n let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\n let modality = useInteractionModality();\n let {visuallyHiddenProps} = useVisuallyHidden();\n\n useFormReset(props.selectRef, state.selectedKey, state.setSelectedKey);\n useFormValidation({\n validationBehavior,\n focus: () => triggerRef.current.focus()\n }, state, props.selectRef);\n\n // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.\n // In Firefox, there must be a <label> to identify the <select> whereas other browsers\n // seem to identify it just by surrounding text.\n // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a\n // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>\n // non tabbable with tabIndex={-1}.\n //\n // In mobile browsers, there are next/previous buttons above the software keyboard for navigating\n // between fields in a form. These only support native form inputs that are tabbable. In order to\n // support those, an additional hidden input is used to marshall focus to the button. It is tabbable\n // except when the button is focused, so that shift tab works properly to go to the actual previous\n // input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes\n // the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to\n // prevent Safari from zooming in on the input when it is focused.\n //\n // If the current interaction modality is null, then the user hasn't interacted with the page yet.\n // In this case, we set the tabIndex to -1 on the input element so that automated accessibility\n // checkers don't throw false-positives about focusable elements inside an aria-hidden parent.\n return {\n containerProps: {\n ...visuallyHiddenProps,\n 'aria-hidden': true,\n ['data-hidden-select-ignore']: true,\n ['data-a11y-ignore']: 'aria-hidden-focus'\n },\n inputProps: {\n type: 'text',\n tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,\n style: {fontSize: 16},\n onFocus: () => triggerRef.current.focus(),\n disabled: isDisabled\n },\n selectProps: {\n tabIndex: -1,\n autoComplete,\n disabled: isDisabled,\n required: validationBehavior === 'native' && isRequired,\n name,\n value: state.selectedKey ?? '',\n onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value)\n }\n };\n}\n\n/**\n * Renders a hidden native `<select>` element, which can be used to support browser\n * form autofill, mobile form navigation, and native form submission.\n */\nexport function HiddenSelect<T>(props: HiddenSelectProps<T>) {\n let {state, triggerRef, label, name, isDisabled} = props;\n let selectRef = useRef(null);\n let {containerProps, inputProps, selectProps} = useHiddenSelect({...props, selectRef}, state, triggerRef);\n\n // If used in a <form>, use a hidden input so the value can be submitted to a server.\n // If the collection isn't too big, use a hidden <select> element for this so that browser\n // autofill will work. Otherwise, use an <input type=\"hidden\">.\n if (state.collection.size <= 300) {\n return (\n <div {...containerProps} data-testid=\"hidden-select-container\">\n <input {...inputProps} />\n <label>\n {label}\n <select {...selectProps} ref={selectRef}>\n <option />\n {[...state.collection.getKeys()].map(key => {\n let item = state.collection.getItem(key);\n if (item.type === 'item') {\n return (\n <option\n key={item.key}\n value={item.key}>\n {item.textValue}\n </option>\n );\n }\n })}\n </select>\n </label>\n </div>\n );\n } else if (name) {\n return (\n <input\n type=\"hidden\"\n autoComplete={selectProps.autoComplete}\n name={name}\n disabled={isDisabled}\n value={state.selectedKey ?? ''} />\n );\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/select/src/index.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 */\nexport {useSelect} from './useSelect';\nexport {useHiddenSelect, HiddenSelect} from './HiddenSelect';\nexport type {AriaSelectOptions, SelectAria} from './useSelect';\nexport type {AriaHiddenSelectProps, HiddenSelectProps} from './HiddenSelect';\nexport type {AriaSelectProps} from '@react-types/select';\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AriaButtonProps } from "@react-types/button";
|
|
2
2
|
import { AriaListBoxOptions } from "@react-aria/listbox";
|
|
3
3
|
import { AriaSelectProps } from "@react-types/select";
|
|
4
|
-
import { DOMAttributes, FocusableElement, KeyboardDelegate, ValidationResult } from "@react-types/shared";
|
|
4
|
+
import { DOMAttributes, FocusableElement, KeyboardDelegate, ValidationResult, Key } from "@react-types/shared";
|
|
5
5
|
import React, { RefObject, ReactNode } from "react";
|
|
6
6
|
import { SelectState } from "@react-stately/select";
|
|
7
7
|
export interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {
|
|
@@ -303,7 +303,7 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
303
303
|
disabled: boolean;
|
|
304
304
|
required: boolean;
|
|
305
305
|
name: string;
|
|
306
|
-
value:
|
|
306
|
+
value: Key;
|
|
307
307
|
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
|
|
308
308
|
};
|
|
309
309
|
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var $63cuq$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $63cuq$react = require("react");
|
|
3
|
+
var $63cuq$reactariaselection = require("@react-aria/selection");
|
|
4
|
+
var $63cuq$reactariainteractions = require("@react-aria/interactions");
|
|
5
|
+
var $63cuq$reactariai18n = require("@react-aria/i18n");
|
|
6
|
+
var $63cuq$reactarialabel = require("@react-aria/label");
|
|
7
|
+
var $63cuq$reactariamenu = require("@react-aria/menu");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function $parcel$export(e, n, v, s) {
|
|
11
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
$parcel$export(module.exports, "selectData", () => $23a1e93dc7fa8653$export$703601b7e90536f8);
|
|
15
|
+
$parcel$export(module.exports, "useSelect", () => $23a1e93dc7fa8653$export$e64b2f635402ca43);
|
|
16
|
+
/*
|
|
17
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
18
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
20
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
23
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
24
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
25
|
+
* governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const $23a1e93dc7fa8653$export$703601b7e90536f8 = new WeakMap();
|
|
34
|
+
function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
|
|
35
|
+
let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = "aria" } = props;
|
|
36
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
37
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
38
|
+
let collator = (0, $63cuq$reactariai18n.useCollator)({
|
|
39
|
+
usage: "search",
|
|
40
|
+
sensitivity: "base"
|
|
41
|
+
});
|
|
42
|
+
let delegate = (0, $63cuq$react.useMemo)(()=>keyboardDelegate || new (0, $63cuq$reactariaselection.ListKeyboardDelegate)(state.collection, state.disabledKeys, null, collator), [
|
|
43
|
+
keyboardDelegate,
|
|
44
|
+
state.collection,
|
|
45
|
+
state.disabledKeys,
|
|
46
|
+
collator
|
|
47
|
+
]);
|
|
48
|
+
let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $63cuq$reactariamenu.useMenuTrigger)({
|
|
49
|
+
isDisabled: isDisabled,
|
|
50
|
+
type: "listbox"
|
|
51
|
+
}, state, ref);
|
|
52
|
+
let onKeyDown = (e)=>{
|
|
53
|
+
switch(e.key){
|
|
54
|
+
case "ArrowLeft":
|
|
55
|
+
{
|
|
56
|
+
// prevent scrolling containers
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
59
|
+
if (key) state.setSelectedKey(key);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case "ArrowRight":
|
|
63
|
+
{
|
|
64
|
+
// prevent scrolling containers
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
67
|
+
if (key) state.setSelectedKey(key);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
let { typeSelectProps: typeSelectProps } = (0, $63cuq$reactariaselection.useTypeSelect)({
|
|
73
|
+
keyboardDelegate: delegate,
|
|
74
|
+
selectionManager: state.selectionManager,
|
|
75
|
+
onTypeSelect (key) {
|
|
76
|
+
state.setSelectedKey(key);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
|
|
80
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $63cuq$reactarialabel.useField)({
|
|
81
|
+
...props,
|
|
82
|
+
labelElementType: "span",
|
|
83
|
+
isInvalid: isInvalid,
|
|
84
|
+
errorMessage: props.errorMessage || validationErrors
|
|
85
|
+
});
|
|
86
|
+
typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;
|
|
87
|
+
delete typeSelectProps.onKeyDownCapture;
|
|
88
|
+
let domProps = (0, $63cuq$reactariautils.filterDOMProps)(props, {
|
|
89
|
+
labelable: true
|
|
90
|
+
});
|
|
91
|
+
let triggerProps = (0, $63cuq$reactariautils.mergeProps)(typeSelectProps, menuTriggerProps, fieldProps);
|
|
92
|
+
let valueId = (0, $63cuq$reactariautils.useId)();
|
|
93
|
+
$23a1e93dc7fa8653$export$703601b7e90536f8.set(state, {
|
|
94
|
+
isDisabled: isDisabled,
|
|
95
|
+
isRequired: isRequired,
|
|
96
|
+
name: name,
|
|
97
|
+
validationBehavior: validationBehavior
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
labelProps: {
|
|
101
|
+
...labelProps,
|
|
102
|
+
onClick: ()=>{
|
|
103
|
+
if (!props.isDisabled) {
|
|
104
|
+
ref.current.focus();
|
|
105
|
+
// Show the focus ring so the user knows where focus went
|
|
106
|
+
(0, $63cuq$reactariainteractions.setInteractionModality)("keyboard");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
triggerProps: (0, $63cuq$reactariautils.mergeProps)(domProps, {
|
|
111
|
+
...triggerProps,
|
|
112
|
+
isDisabled: isDisabled,
|
|
113
|
+
onKeyDown: (0, $63cuq$reactariautils.chain)(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),
|
|
114
|
+
onKeyUp: props.onKeyUp,
|
|
115
|
+
"aria-labelledby": [
|
|
116
|
+
valueId,
|
|
117
|
+
triggerProps["aria-labelledby"],
|
|
118
|
+
triggerProps["aria-label"] && !triggerProps["aria-labelledby"] ? triggerProps.id : null
|
|
119
|
+
].filter(Boolean).join(" "),
|
|
120
|
+
onFocus (e) {
|
|
121
|
+
if (state.isFocused) return;
|
|
122
|
+
if (props.onFocus) props.onFocus(e);
|
|
123
|
+
if (props.onFocusChange) props.onFocusChange(true);
|
|
124
|
+
state.setFocused(true);
|
|
125
|
+
},
|
|
126
|
+
onBlur (e) {
|
|
127
|
+
if (state.isOpen) return;
|
|
128
|
+
if (props.onBlur) props.onBlur(e);
|
|
129
|
+
if (props.onFocusChange) props.onFocusChange(false);
|
|
130
|
+
state.setFocused(false);
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
valueProps: {
|
|
134
|
+
id: valueId
|
|
135
|
+
},
|
|
136
|
+
menuProps: {
|
|
137
|
+
...menuProps,
|
|
138
|
+
autoFocus: state.focusStrategy || true,
|
|
139
|
+
shouldSelectOnPressUp: true,
|
|
140
|
+
shouldFocusOnHover: true,
|
|
141
|
+
disallowEmptySelection: true,
|
|
142
|
+
linkBehavior: "selection",
|
|
143
|
+
onBlur: (e)=>{
|
|
144
|
+
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
145
|
+
if (props.onBlur) props.onBlur(e);
|
|
146
|
+
if (props.onFocusChange) props.onFocusChange(false);
|
|
147
|
+
state.setFocused(false);
|
|
148
|
+
},
|
|
149
|
+
"aria-labelledby": [
|
|
150
|
+
fieldProps["aria-labelledby"],
|
|
151
|
+
triggerProps["aria-label"] && !fieldProps["aria-labelledby"] ? triggerProps.id : null
|
|
152
|
+
].filter(Boolean).join(" ")
|
|
153
|
+
},
|
|
154
|
+
descriptionProps: descriptionProps,
|
|
155
|
+
errorMessageProps: errorMessageProps,
|
|
156
|
+
isInvalid: isInvalid,
|
|
157
|
+
validationErrors: validationErrors,
|
|
158
|
+
validationDetails: validationDetails
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
//# sourceMappingURL=useSelect.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAgC;IAC/G,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,sBACJ,qBAAqB,QACtB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,gCAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAM,oBAAoB,IAAI,CAAA,GAAA,8CAAmB,EAAE,MAAM,UAAU,EAAE,MAAM,YAAY,EAAE,MAAM,WAAW;QAAC;QAAkB,MAAM,UAAU;QAAE,MAAM,YAAY;QAAE;KAAS;IAEnM,IAAI,oBAAC,gBAAgB,aAAE,SAAS,EAAC,GAAG,CAAA,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mBAAmB;gBACjB,UAAU,CAAC,kBAAkB;gBAC7B,YAAY,CAAC,aAAa,IAAI,CAAC,UAAU,CAAC,kBAAkB,GAAG,aAAa,EAAE,GAAG;aAClF,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;QACzB;0BACA;2BACA;mBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/select/src/useSelect.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 {AriaSelectProps} from '@react-types/select';\nimport {chain, filterDOMProps, mergeProps, useId} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, KeyboardDelegate, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, RefObject, useMemo} from 'react';\nimport {ListKeyboardDelegate, useTypeSelect} from '@react-aria/selection';\nimport {SelectState} from '@react-stately/select';\nimport {setInteractionModality} from '@react-aria/interactions';\nimport {useCollator} from '@react-aria/i18n';\nimport {useField} from '@react-aria/label';\nimport {useMenuTrigger} from '@react-aria/menu';\n\nexport interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {\n /**\n * An optional keyboard delegate implementation for type to select,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\nexport interface SelectAria<T> extends ValidationResult {\n /** Props for the label element. */\n labelProps: DOMAttributes,\n\n /** Props for the popup trigger element. */\n triggerProps: AriaButtonProps,\n\n /** Props for the element representing the selected value. */\n valueProps: DOMAttributes,\n\n /** Props for the popup. */\n menuProps: AriaListBoxOptions<T>,\n\n /** Props for the select's description element, if any. */\n descriptionProps: DOMAttributes,\n\n /** Props for the select's error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\ninterface SelectData {\n isDisabled?: boolean,\n isRequired?: boolean,\n name?: string,\n validationBehavior?: 'aria' | 'native'\n}\n\nexport const selectData = new WeakMap<SelectState<any>, SelectData>();\n\n/**\n * Provides the behavior and accessibility implementation for a select component.\n * A select displays a collapsible list of options and allows a user to select one of them.\n * @param props - Props for the select.\n * @param state - State for the select, as returned by `useListState`.\n */\nexport function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<FocusableElement>): SelectAria<T> {\n let {\n keyboardDelegate,\n isDisabled,\n isRequired,\n name,\n validationBehavior = 'aria'\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(state.collection, state.disabledKeys, null, collator), [keyboardDelegate, state.collection, state.disabledKeys, collator]);\n\n let {menuTriggerProps, menuProps} = useMenuTrigger<T>(\n {\n isDisabled,\n type: 'listbox'\n },\n state,\n ref\n );\n\n let onKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'ArrowLeft': {\n // prevent scrolling containers\n e.preventDefault();\n\n let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();\n if (key) {\n state.setSelectedKey(key);\n }\n break;\n }\n case 'ArrowRight': {\n // prevent scrolling containers\n e.preventDefault();\n\n let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();\n if (key) {\n state.setSelectedKey(key);\n }\n break;\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: state.selectionManager,\n onTypeSelect(key) {\n state.setSelectedKey(key);\n }\n });\n\n let {isInvalid, validationErrors, validationDetails} = state.displayValidation;\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n labelElementType: 'span',\n isInvalid,\n errorMessage: props.errorMessage || validationErrors\n });\n\n typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;\n delete typeSelectProps.onKeyDownCapture;\n\n let domProps = filterDOMProps(props, {labelable: true});\n let triggerProps = mergeProps(typeSelectProps, menuTriggerProps, fieldProps);\n\n let valueId = useId();\n\n selectData.set(state, {\n isDisabled,\n isRequired,\n name,\n validationBehavior\n });\n\n return {\n labelProps: {\n ...labelProps,\n onClick: () => {\n if (!props.isDisabled) {\n ref.current.focus();\n\n // Show the focus ring so the user knows where focus went\n setInteractionModality('keyboard');\n }\n }\n },\n triggerProps: mergeProps(domProps, {\n ...triggerProps,\n isDisabled,\n onKeyDown: chain(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),\n onKeyUp: props.onKeyUp,\n 'aria-labelledby': [\n valueId,\n triggerProps['aria-labelledby'],\n triggerProps['aria-label'] && !triggerProps['aria-labelledby'] ? triggerProps.id : null\n ].filter(Boolean).join(' '),\n onFocus(e: FocusEvent) {\n if (state.isFocused) {\n return;\n }\n\n if (props.onFocus) {\n props.onFocus(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(true);\n }\n\n state.setFocused(true);\n },\n onBlur(e: FocusEvent) {\n if (state.isOpen) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n }\n }),\n valueProps: {\n id: valueId\n },\n menuProps: {\n ...menuProps,\n autoFocus: state.focusStrategy || true,\n shouldSelectOnPressUp: true,\n shouldFocusOnHover: true,\n disallowEmptySelection: true,\n linkBehavior: 'selection',\n onBlur: (e) => {\n if (e.currentTarget.contains(e.relatedTarget as Node)) {\n return;\n }\n\n if (props.onBlur) {\n props.onBlur(e);\n }\n\n if (props.onFocusChange) {\n props.onFocusChange(false);\n }\n\n state.setFocused(false);\n },\n 'aria-labelledby': [\n fieldProps['aria-labelledby'],\n triggerProps['aria-label'] && !fieldProps['aria-labelledby'] ? triggerProps.id : null\n ].filter(Boolean).join(' ')\n },\n descriptionProps,\n errorMessageProps,\n isInvalid,\n validationErrors,\n validationDetails\n };\n}\n"],"names":[],"version":3,"file":"useSelect.main.js.map"}
|