@react-aria/select 3.14.4-nightly.4555 → 3.14.4-nightly.4558

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,169 +1,5 @@
1
- import {filterDOMProps as $thkiX$filterDOMProps, mergeProps as $thkiX$mergeProps, useId as $thkiX$useId, chain as $thkiX$chain, useFormReset as $thkiX$useFormReset} from "@react-aria/utils";
2
- import $thkiX$react, {useMemo as $thkiX$useMemo, useRef as $thkiX$useRef} from "react";
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.mjs";
2
+ import {HiddenSelect as $bdd25dc72710631f$export$cbd84cdb2e668835, useHiddenSelect as $bdd25dc72710631f$export$f809e80f58e251d1} from "./HiddenSelect.mjs";
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/main.js CHANGED
@@ -1,36 +1,15 @@
1
- var $j4fa6$reactariautils = require("@react-aria/utils");
2
- var $j4fa6$react = require("react");
3
- var $j4fa6$reactariaselection = require("@react-aria/selection");
4
- var $j4fa6$reactariainteractions = require("@react-aria/interactions");
5
- var $j4fa6$reactariai18n = require("@react-aria/i18n");
6
- var $j4fa6$reactarialabel = require("@react-aria/label");
7
- var $j4fa6$reactariamenu = require("@react-aria/menu");
8
- var $j4fa6$reactariaform = require("@react-aria/form");
9
- var $j4fa6$reactariavisuallyhidden = require("@react-aria/visually-hidden");
1
+ var $23a1e93dc7fa8653$exports = require("./useSelect.main.js");
2
+ var $6eae0e0872a4cdd4$exports = require("./HiddenSelect.main.js");
10
3
 
11
4
 
12
5
  function $parcel$export(e, n, v, s) {
13
6
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
7
  }
15
8
 
16
- function $parcel$interopDefault(a) {
17
- return a && a.__esModule ? a.default : a;
18
- }
19
-
20
- $parcel$export(module.exports, "useSelect", () => $23a1e93dc7fa8653$export$e64b2f635402ca43);
21
- $parcel$export(module.exports, "useHiddenSelect", () => $6eae0e0872a4cdd4$export$f809e80f58e251d1);
22
- $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$export$cbd84cdb2e668835);
9
+ $parcel$export(module.exports, "useSelect", () => $23a1e93dc7fa8653$exports.useSelect);
10
+ $parcel$export(module.exports, "useHiddenSelect", () => $6eae0e0872a4cdd4$exports.useHiddenSelect);
11
+ $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$exports.HiddenSelect);
23
12
  /*
24
- * Copyright 2020 Adobe. All rights reserved.
25
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
26
- * you may not use this file except in compliance with the License. You may obtain a copy
27
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
28
- *
29
- * Unless required by applicable law or agreed to in writing, software distributed under
30
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
31
- * OF ANY KIND, either express or implied. See the License for the specific language
32
- * governing permissions and limitations under the License.
33
- */ /*
34
13
  * Copyright 2020 Adobe. All rights reserved.
35
14
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
36
15
  * you may not use this file except in compliance with the License. You may obtain a copy
@@ -44,249 +23,4 @@ $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$export$cb
44
23
 
45
24
 
46
25
 
47
-
48
-
49
-
50
- const $23a1e93dc7fa8653$export$703601b7e90536f8 = new WeakMap();
51
- function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
52
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = "aria" } = props;
53
- // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
54
- // When virtualized, the layout object will be passed in as a prop and override this.
55
- let collator = (0, $j4fa6$reactariai18n.useCollator)({
56
- usage: "search",
57
- sensitivity: "base"
58
- });
59
- let delegate = (0, $j4fa6$react.useMemo)(()=>keyboardDelegate || new (0, $j4fa6$reactariaselection.ListKeyboardDelegate)(state.collection, state.disabledKeys, null, collator), [
60
- keyboardDelegate,
61
- state.collection,
62
- state.disabledKeys,
63
- collator
64
- ]);
65
- let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $j4fa6$reactariamenu.useMenuTrigger)({
66
- isDisabled: isDisabled,
67
- type: "listbox"
68
- }, state, ref);
69
- let onKeyDown = (e)=>{
70
- switch(e.key){
71
- case "ArrowLeft":
72
- {
73
- // prevent scrolling containers
74
- e.preventDefault();
75
- let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
76
- if (key) state.setSelectedKey(key);
77
- break;
78
- }
79
- case "ArrowRight":
80
- {
81
- // prevent scrolling containers
82
- e.preventDefault();
83
- let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
84
- if (key) state.setSelectedKey(key);
85
- break;
86
- }
87
- }
88
- };
89
- let { typeSelectProps: typeSelectProps } = (0, $j4fa6$reactariaselection.useTypeSelect)({
90
- keyboardDelegate: delegate,
91
- selectionManager: state.selectionManager,
92
- onTypeSelect (key) {
93
- state.setSelectedKey(key);
94
- }
95
- });
96
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
97
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $j4fa6$reactarialabel.useField)({
98
- ...props,
99
- labelElementType: "span",
100
- isInvalid: isInvalid,
101
- errorMessage: props.errorMessage || validationErrors
102
- });
103
- typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;
104
- delete typeSelectProps.onKeyDownCapture;
105
- let domProps = (0, $j4fa6$reactariautils.filterDOMProps)(props, {
106
- labelable: true
107
- });
108
- let triggerProps = (0, $j4fa6$reactariautils.mergeProps)(typeSelectProps, menuTriggerProps, fieldProps);
109
- let valueId = (0, $j4fa6$reactariautils.useId)();
110
- $23a1e93dc7fa8653$export$703601b7e90536f8.set(state, {
111
- isDisabled: isDisabled,
112
- isRequired: isRequired,
113
- name: name,
114
- validationBehavior: validationBehavior
115
- });
116
- return {
117
- labelProps: {
118
- ...labelProps,
119
- onClick: ()=>{
120
- if (!props.isDisabled) {
121
- ref.current.focus();
122
- // Show the focus ring so the user knows where focus went
123
- (0, $j4fa6$reactariainteractions.setInteractionModality)("keyboard");
124
- }
125
- }
126
- },
127
- triggerProps: (0, $j4fa6$reactariautils.mergeProps)(domProps, {
128
- ...triggerProps,
129
- isDisabled: isDisabled,
130
- onKeyDown: (0, $j4fa6$reactariautils.chain)(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),
131
- onKeyUp: props.onKeyUp,
132
- "aria-labelledby": [
133
- valueId,
134
- triggerProps["aria-labelledby"],
135
- triggerProps["aria-label"] && !triggerProps["aria-labelledby"] ? triggerProps.id : null
136
- ].filter(Boolean).join(" "),
137
- onFocus (e) {
138
- if (state.isFocused) return;
139
- if (props.onFocus) props.onFocus(e);
140
- if (props.onFocusChange) props.onFocusChange(true);
141
- state.setFocused(true);
142
- },
143
- onBlur (e) {
144
- if (state.isOpen) return;
145
- if (props.onBlur) props.onBlur(e);
146
- if (props.onFocusChange) props.onFocusChange(false);
147
- state.setFocused(false);
148
- }
149
- }),
150
- valueProps: {
151
- id: valueId
152
- },
153
- menuProps: {
154
- ...menuProps,
155
- autoFocus: state.focusStrategy || true,
156
- shouldSelectOnPressUp: true,
157
- shouldFocusOnHover: true,
158
- disallowEmptySelection: true,
159
- linkBehavior: "selection",
160
- onBlur: (e)=>{
161
- if (e.currentTarget.contains(e.relatedTarget)) return;
162
- if (props.onBlur) props.onBlur(e);
163
- if (props.onFocusChange) props.onFocusChange(false);
164
- state.setFocused(false);
165
- },
166
- "aria-labelledby": [
167
- fieldProps["aria-labelledby"],
168
- triggerProps["aria-label"] && !fieldProps["aria-labelledby"] ? triggerProps.id : null
169
- ].filter(Boolean).join(" ")
170
- },
171
- descriptionProps: descriptionProps,
172
- errorMessageProps: errorMessageProps,
173
- isInvalid: isInvalid,
174
- validationErrors: validationErrors,
175
- validationDetails: validationDetails
176
- };
177
- }
178
-
179
-
180
- /*
181
- * Copyright 2020 Adobe. All rights reserved.
182
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
183
- * you may not use this file except in compliance with the License. You may obtain a copy
184
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
185
- *
186
- * Unless required by applicable law or agreed to in writing, software distributed under
187
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
188
- * OF ANY KIND, either express or implied. See the License for the specific language
189
- * governing permissions and limitations under the License.
190
- */
191
-
192
-
193
-
194
-
195
-
196
- function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
197
- let data = (0, $23a1e93dc7fa8653$export$703601b7e90536f8).get(state) || {};
198
- let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
199
- let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
200
- let modality = (0, $j4fa6$reactariainteractions.useInteractionModality)();
201
- let { visuallyHiddenProps: visuallyHiddenProps } = (0, $j4fa6$reactariavisuallyhidden.useVisuallyHidden)();
202
- (0, $j4fa6$reactariautils.useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
203
- (0, $j4fa6$reactariaform.useFormValidation)({
204
- validationBehavior: validationBehavior,
205
- focus: ()=>triggerRef.current.focus()
206
- }, state, props.selectRef);
207
- var _state_selectedKey;
208
- // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
209
- // In Firefox, there must be a <label> to identify the <select> whereas other browsers
210
- // seem to identify it just by surrounding text.
211
- // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
212
- // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
213
- // non tabbable with tabIndex={-1}.
214
- //
215
- // In mobile browsers, there are next/previous buttons above the software keyboard for navigating
216
- // between fields in a form. These only support native form inputs that are tabbable. In order to
217
- // support those, an additional hidden input is used to marshall focus to the button. It is tabbable
218
- // except when the button is focused, so that shift tab works properly to go to the actual previous
219
- // input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
220
- // the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
221
- // prevent Safari from zooming in on the input when it is focused.
222
- //
223
- // If the current interaction modality is null, then the user hasn't interacted with the page yet.
224
- // In this case, we set the tabIndex to -1 on the input element so that automated accessibility
225
- // checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
226
- return {
227
- containerProps: {
228
- ...visuallyHiddenProps,
229
- "aria-hidden": true,
230
- ["data-hidden-select-ignore"]: true,
231
- ["data-a11y-ignore"]: "aria-hidden-focus"
232
- },
233
- inputProps: {
234
- type: "text",
235
- tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
236
- style: {
237
- fontSize: 16
238
- },
239
- onFocus: ()=>triggerRef.current.focus(),
240
- disabled: isDisabled
241
- },
242
- selectProps: {
243
- tabIndex: -1,
244
- autoComplete: autoComplete,
245
- disabled: isDisabled,
246
- required: validationBehavior === "native" && isRequired,
247
- name: name,
248
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : "",
249
- onChange: (e)=>state.setSelectedKey(e.target.value)
250
- }
251
- };
252
- }
253
- function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
254
- let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
255
- let selectRef = (0, $j4fa6$react.useRef)(null);
256
- let { containerProps: containerProps, inputProps: inputProps, selectProps: selectProps } = $6eae0e0872a4cdd4$export$f809e80f58e251d1({
257
- ...props,
258
- selectRef: selectRef
259
- }, state, triggerRef);
260
- var _state_selectedKey;
261
- // If used in a <form>, use a hidden input so the value can be submitted to a server.
262
- // If the collection isn't too big, use a hidden <select> element for this so that browser
263
- // autofill will work. Otherwise, use an <input type="hidden">.
264
- if (state.collection.size <= 300) return /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("div", {
265
- ...containerProps,
266
- "data-testid": "hidden-select-container"
267
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("input", inputProps), /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("label", null, label, /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("select", {
268
- ...selectProps,
269
- ref: selectRef
270
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("option", null), [
271
- ...state.collection.getKeys()
272
- ].map((key)=>{
273
- let item = state.collection.getItem(key);
274
- if (item.type === "item") return /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("option", {
275
- key: item.key,
276
- value: item.key
277
- }, item.textValue);
278
- }))));
279
- else if (name) return /*#__PURE__*/ (0, ($parcel$interopDefault($j4fa6$react))).createElement("input", {
280
- type: "hidden",
281
- autoComplete: selectProps.autoComplete,
282
- name: name,
283
- disabled: isDisabled,
284
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ""
285
- });
286
- return null;
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AAE,WAAW,EAAC,GAAG,0CAAgB;QAAC,GAAG,KAAK;mBAAE;IAAS,GAAG,OAAO;QAoCjF;IAlCb,qFAAqF;IACrF,0FAA0F;IAC1F,+DAA+D;IAC/D,IAAI,MAAM,UAAU,CAAC,IAAI,IAAI,KAC3B,qBACE,0DAAC;QAAK,GAAG,cAAc;QAAE,eAAY;qBACnC,0DAAC,SAAU,2BACX,0DAAC,eACE,qBACD,0DAAC;QAAQ,GAAG,WAAW;QAAE,KAAK;qBAC5B,0DAAC,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,0DAAC;YACC,KAAK,KAAK,GAAG;YACb,OAAO,KAAK,GAAG;WACd,KAAK,SAAS;IAIvB;SAKH,IAAI,MACT,qBACE,0DAAC;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":"main.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":"main.js.map"}