@react-aria/select 3.14.10 → 3.15.0
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/LICENSE +201 -0
- package/dist/HiddenSelect.main.js +9 -25
- package/dist/HiddenSelect.main.js.map +1 -1
- package/dist/HiddenSelect.mjs +9 -25
- package/dist/HiddenSelect.module.js +9 -25
- package/dist/HiddenSelect.module.js.map +1 -1
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelect.main.js +7 -4
- package/dist/useSelect.main.js.map +1 -1
- package/dist/useSelect.mjs +7 -4
- package/dist/useSelect.module.js +7 -4
- package/dist/useSelect.module.js.map +1 -1
- package/package.json +19 -18
- package/src/HiddenSelect.tsx +4 -23
- package/src/useSelect.ts +6 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2019 Adobe
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -2,7 +2,6 @@ var $23a1e93dc7fa8653$exports = require("./useSelect.main.js");
|
|
|
2
2
|
var $ccxQv$react = require("react");
|
|
3
3
|
var $ccxQv$reactariautils = require("@react-aria/utils");
|
|
4
4
|
var $ccxQv$reactariaform = require("@react-aria/form");
|
|
5
|
-
var $ccxQv$reactariainteractions = require("@react-aria/interactions");
|
|
6
5
|
var $ccxQv$reactariavisuallyhidden = require("@react-aria/visually-hidden");
|
|
7
6
|
|
|
8
7
|
|
|
@@ -31,17 +30,18 @@ $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$export$cb
|
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
|
|
34
|
-
|
|
35
33
|
function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
36
34
|
let data = (0, $23a1e93dc7fa8653$exports.selectData).get(state) || {};
|
|
37
35
|
let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
|
|
38
36
|
let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
|
|
39
|
-
let modality = (0, $ccxQv$reactariainteractions.useInteractionModality)();
|
|
40
37
|
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $ccxQv$reactariavisuallyhidden.useVisuallyHidden)();
|
|
41
38
|
(0, $ccxQv$reactariautils.useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
|
|
42
39
|
(0, $ccxQv$reactariaform.useFormValidation)({
|
|
43
40
|
validationBehavior: validationBehavior,
|
|
44
|
-
focus: ()=>
|
|
41
|
+
focus: ()=>{
|
|
42
|
+
var _triggerRef_current;
|
|
43
|
+
return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
44
|
+
}
|
|
45
45
|
}, state, props.selectRef);
|
|
46
46
|
var _state_selectedKey;
|
|
47
47
|
// In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
|
|
@@ -50,18 +50,6 @@ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
50
50
|
// The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
|
|
51
51
|
// 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
|
|
52
52
|
// non tabbable with tabIndex={-1}.
|
|
53
|
-
//
|
|
54
|
-
// In mobile browsers, there are next/previous buttons above the software keyboard for navigating
|
|
55
|
-
// between fields in a form. These only support native form inputs that are tabbable. In order to
|
|
56
|
-
// support those, an additional hidden input is used to marshall focus to the button. It is tabbable
|
|
57
|
-
// except when the button is focused, so that shift tab works properly to go to the actual previous
|
|
58
|
-
// input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
|
|
59
|
-
// the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
|
|
60
|
-
// prevent Safari from zooming in on the input when it is focused.
|
|
61
|
-
//
|
|
62
|
-
// If the current interaction modality is null, then the user hasn't interacted with the page yet.
|
|
63
|
-
// In this case, we set the tabIndex to -1 on the input element so that automated accessibility
|
|
64
|
-
// checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
|
|
65
53
|
return {
|
|
66
54
|
containerProps: {
|
|
67
55
|
...visuallyHiddenProps,
|
|
@@ -72,13 +60,9 @@ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
72
60
|
['data-a11y-ignore']: 'aria-hidden-focus'
|
|
73
61
|
},
|
|
74
62
|
inputProps: {
|
|
75
|
-
type: 'text',
|
|
76
|
-
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
|
|
77
63
|
style: {
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
onFocus: ()=>triggerRef.current.focus(),
|
|
81
|
-
disabled: isDisabled
|
|
64
|
+
display: 'none'
|
|
65
|
+
}
|
|
82
66
|
},
|
|
83
67
|
selectProps: {
|
|
84
68
|
tabIndex: -1,
|
|
@@ -94,7 +78,7 @@ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
94
78
|
function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
|
|
95
79
|
let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
|
|
96
80
|
let selectRef = (0, $ccxQv$react.useRef)(null);
|
|
97
|
-
let { containerProps: containerProps,
|
|
81
|
+
let { containerProps: containerProps, selectProps: selectProps } = $6eae0e0872a4cdd4$export$f809e80f58e251d1({
|
|
98
82
|
...props,
|
|
99
83
|
selectRef: selectRef
|
|
100
84
|
}, state, triggerRef);
|
|
@@ -105,14 +89,14 @@ function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
|
|
|
105
89
|
if (state.collection.size <= 300) return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("div", {
|
|
106
90
|
...containerProps,
|
|
107
91
|
"data-testid": "hidden-select-container"
|
|
108
|
-
}, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("
|
|
92
|
+
}, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("label", null, label, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("select", {
|
|
109
93
|
...selectProps,
|
|
110
94
|
ref: selectRef
|
|
111
95
|
}, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("option", null), [
|
|
112
96
|
...state.collection.getKeys()
|
|
113
97
|
].map((key)=>{
|
|
114
98
|
let item = state.collection.getItem(key);
|
|
115
|
-
if (item.type === 'item') return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("option", {
|
|
99
|
+
if (item && item.type === 'item') return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("option", {
|
|
116
100
|
key: item.key,
|
|
117
101
|
value: item.key
|
|
118
102
|
}, item.textValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuDM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAA8C;IACtI,IAAI,OAAO,CAAA,GAAA,oCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,gBAAC,YAAY,QAAE,OAAO,KAAK,IAAI,cAAE,aAAa,KAAK,UAAU,EAAC,GAAG;IACrE,IAAI,sBAAC,kBAAkB,cAAE,UAAU,EAAC,GAAG;IACvC,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,gDAAgB;IAE5C,CAAA,GAAA,kCAAW,EAAE,MAAM,SAAS,EAAE,MAAM,WAAW,EAAE,MAAM,cAAc;IACrE,C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QACpC,IAAI,QAAQ,KAAK,IAAI,KAAK,QACxB,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/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 */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport React, {ReactNode, 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 {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 | null>\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n /** A ref to the hidden `<select>` element. */\n selectRef?: RefObject<HTMLSelectElement | null>\n}\n\nexport interface HiddenSelectAria {\n /** Props for the container element. */\n containerProps: React.HTMLAttributes<FocusableElement>,\n\n /** Props for the hidden input element. */\n inputProps: React.InputHTMLAttributes<HTMLInputElement>,\n\n /** Props for the hidden select element. */\n selectProps: React.SelectHTMLAttributes<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 | null>): HiddenSelectAria {\n let data = selectData.get(state) || {};\n let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\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 return {\n containerProps: {\n ...visuallyHiddenProps,\n 'aria-hidden': true,\n // @ts-ignore\n ['data-react-aria-prevent-focus']: true,\n // @ts-ignore\n ['data-a11y-ignore']: 'aria-hidden-focus'\n },\n inputProps: {\n style: {display: 'none'}\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, 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 <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 && 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":"HiddenSelect.main.js.map"}
|
package/dist/HiddenSelect.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSele
|
|
|
2
2
|
import $8BE50$react, {useRef as $8BE50$useRef} from "react";
|
|
3
3
|
import {useFormReset as $8BE50$useFormReset} from "@react-aria/utils";
|
|
4
4
|
import {useFormValidation as $8BE50$useFormValidation} from "@react-aria/form";
|
|
5
|
-
import {useInteractionModality as $8BE50$useInteractionModality} from "@react-aria/interactions";
|
|
6
5
|
import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
7
6
|
|
|
8
7
|
/*
|
|
@@ -20,17 +19,18 @@ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visuall
|
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
|
|
23
|
-
|
|
24
22
|
function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
25
23
|
let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
|
|
26
24
|
let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
|
|
27
25
|
let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
|
|
28
|
-
let modality = (0, $8BE50$useInteractionModality)();
|
|
29
26
|
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
|
|
30
27
|
(0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
|
|
31
28
|
(0, $8BE50$useFormValidation)({
|
|
32
29
|
validationBehavior: validationBehavior,
|
|
33
|
-
focus: ()=>
|
|
30
|
+
focus: ()=>{
|
|
31
|
+
var _triggerRef_current;
|
|
32
|
+
return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
33
|
+
}
|
|
34
34
|
}, state, props.selectRef);
|
|
35
35
|
var _state_selectedKey;
|
|
36
36
|
// In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
|
|
@@ -39,18 +39,6 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
39
39
|
// The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
|
|
40
40
|
// 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
|
|
41
41
|
// non tabbable with tabIndex={-1}.
|
|
42
|
-
//
|
|
43
|
-
// In mobile browsers, there are next/previous buttons above the software keyboard for navigating
|
|
44
|
-
// between fields in a form. These only support native form inputs that are tabbable. In order to
|
|
45
|
-
// support those, an additional hidden input is used to marshall focus to the button. It is tabbable
|
|
46
|
-
// except when the button is focused, so that shift tab works properly to go to the actual previous
|
|
47
|
-
// input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
|
|
48
|
-
// the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
|
|
49
|
-
// prevent Safari from zooming in on the input when it is focused.
|
|
50
|
-
//
|
|
51
|
-
// If the current interaction modality is null, then the user hasn't interacted with the page yet.
|
|
52
|
-
// In this case, we set the tabIndex to -1 on the input element so that automated accessibility
|
|
53
|
-
// checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
|
|
54
42
|
return {
|
|
55
43
|
containerProps: {
|
|
56
44
|
...visuallyHiddenProps,
|
|
@@ -61,13 +49,9 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
61
49
|
['data-a11y-ignore']: 'aria-hidden-focus'
|
|
62
50
|
},
|
|
63
51
|
inputProps: {
|
|
64
|
-
type: 'text',
|
|
65
|
-
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
|
|
66
52
|
style: {
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
onFocus: ()=>triggerRef.current.focus(),
|
|
70
|
-
disabled: isDisabled
|
|
53
|
+
display: 'none'
|
|
54
|
+
}
|
|
71
55
|
},
|
|
72
56
|
selectProps: {
|
|
73
57
|
tabIndex: -1,
|
|
@@ -83,7 +67,7 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
83
67
|
function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
|
|
84
68
|
let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
|
|
85
69
|
let selectRef = (0, $8BE50$useRef)(null);
|
|
86
|
-
let { containerProps: containerProps,
|
|
70
|
+
let { containerProps: containerProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
|
|
87
71
|
...props,
|
|
88
72
|
selectRef: selectRef
|
|
89
73
|
}, state, triggerRef);
|
|
@@ -94,14 +78,14 @@ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
|
|
|
94
78
|
if (state.collection.size <= 300) return /*#__PURE__*/ (0, $8BE50$react).createElement("div", {
|
|
95
79
|
...containerProps,
|
|
96
80
|
"data-testid": "hidden-select-container"
|
|
97
|
-
}, /*#__PURE__*/ (0, $8BE50$react).createElement("
|
|
81
|
+
}, /*#__PURE__*/ (0, $8BE50$react).createElement("label", null, label, /*#__PURE__*/ (0, $8BE50$react).createElement("select", {
|
|
98
82
|
...selectProps,
|
|
99
83
|
ref: selectRef
|
|
100
84
|
}, /*#__PURE__*/ (0, $8BE50$react).createElement("option", null), [
|
|
101
85
|
...state.collection.getKeys()
|
|
102
86
|
].map((key)=>{
|
|
103
87
|
let item = state.collection.getItem(key);
|
|
104
|
-
if (item.type === 'item') return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
|
|
88
|
+
if (item && item.type === 'item') return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
|
|
105
89
|
key: item.key,
|
|
106
90
|
value: item.key
|
|
107
91
|
}, item.textValue);
|
|
@@ -2,7 +2,6 @@ import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSele
|
|
|
2
2
|
import $8BE50$react, {useRef as $8BE50$useRef} from "react";
|
|
3
3
|
import {useFormReset as $8BE50$useFormReset} from "@react-aria/utils";
|
|
4
4
|
import {useFormValidation as $8BE50$useFormValidation} from "@react-aria/form";
|
|
5
|
-
import {useInteractionModality as $8BE50$useInteractionModality} from "@react-aria/interactions";
|
|
6
5
|
import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
|
|
7
6
|
|
|
8
7
|
/*
|
|
@@ -20,17 +19,18 @@ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visuall
|
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
|
|
23
|
-
|
|
24
22
|
function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
25
23
|
let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
|
|
26
24
|
let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
|
|
27
25
|
let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
|
|
28
|
-
let modality = (0, $8BE50$useInteractionModality)();
|
|
29
26
|
let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
|
|
30
27
|
(0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
|
|
31
28
|
(0, $8BE50$useFormValidation)({
|
|
32
29
|
validationBehavior: validationBehavior,
|
|
33
|
-
focus: ()=>
|
|
30
|
+
focus: ()=>{
|
|
31
|
+
var _triggerRef_current;
|
|
32
|
+
return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
33
|
+
}
|
|
34
34
|
}, state, props.selectRef);
|
|
35
35
|
var _state_selectedKey;
|
|
36
36
|
// In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
|
|
@@ -39,18 +39,6 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
39
39
|
// The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
|
|
40
40
|
// 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
|
|
41
41
|
// non tabbable with tabIndex={-1}.
|
|
42
|
-
//
|
|
43
|
-
// In mobile browsers, there are next/previous buttons above the software keyboard for navigating
|
|
44
|
-
// between fields in a form. These only support native form inputs that are tabbable. In order to
|
|
45
|
-
// support those, an additional hidden input is used to marshall focus to the button. It is tabbable
|
|
46
|
-
// except when the button is focused, so that shift tab works properly to go to the actual previous
|
|
47
|
-
// input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
|
|
48
|
-
// the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
|
|
49
|
-
// prevent Safari from zooming in on the input when it is focused.
|
|
50
|
-
//
|
|
51
|
-
// If the current interaction modality is null, then the user hasn't interacted with the page yet.
|
|
52
|
-
// In this case, we set the tabIndex to -1 on the input element so that automated accessibility
|
|
53
|
-
// checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
|
|
54
42
|
return {
|
|
55
43
|
containerProps: {
|
|
56
44
|
...visuallyHiddenProps,
|
|
@@ -61,13 +49,9 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
61
49
|
['data-a11y-ignore']: 'aria-hidden-focus'
|
|
62
50
|
},
|
|
63
51
|
inputProps: {
|
|
64
|
-
type: 'text',
|
|
65
|
-
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
|
|
66
52
|
style: {
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
onFocus: ()=>triggerRef.current.focus(),
|
|
70
|
-
disabled: isDisabled
|
|
53
|
+
display: 'none'
|
|
54
|
+
}
|
|
71
55
|
},
|
|
72
56
|
selectProps: {
|
|
73
57
|
tabIndex: -1,
|
|
@@ -83,7 +67,7 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
|
|
|
83
67
|
function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
|
|
84
68
|
let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
|
|
85
69
|
let selectRef = (0, $8BE50$useRef)(null);
|
|
86
|
-
let { containerProps: containerProps,
|
|
70
|
+
let { containerProps: containerProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
|
|
87
71
|
...props,
|
|
88
72
|
selectRef: selectRef
|
|
89
73
|
}, state, triggerRef);
|
|
@@ -94,14 +78,14 @@ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
|
|
|
94
78
|
if (state.collection.size <= 300) return /*#__PURE__*/ (0, $8BE50$react).createElement("div", {
|
|
95
79
|
...containerProps,
|
|
96
80
|
"data-testid": "hidden-select-container"
|
|
97
|
-
}, /*#__PURE__*/ (0, $8BE50$react).createElement("
|
|
81
|
+
}, /*#__PURE__*/ (0, $8BE50$react).createElement("label", null, label, /*#__PURE__*/ (0, $8BE50$react).createElement("select", {
|
|
98
82
|
...selectProps,
|
|
99
83
|
ref: selectRef
|
|
100
84
|
}, /*#__PURE__*/ (0, $8BE50$react).createElement("option", null), [
|
|
101
85
|
...state.collection.getKeys()
|
|
102
86
|
].map((key)=>{
|
|
103
87
|
let item = state.collection.getItem(key);
|
|
104
|
-
if (item.type === 'item') return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
|
|
88
|
+
if (item && item.type === 'item') return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
|
|
105
89
|
key: item.key,
|
|
106
90
|
value: item.key
|
|
107
91
|
}, item.textValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuDM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAA8C;IACtI,IAAI,OAAO,CAAA,GAAA,yCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,gBAAC,YAAY,QAAE,OAAO,KAAK,IAAI,cAAE,aAAa,KAAK,UAAU,EAAC,GAAG;IACrE,IAAI,sBAAC,kBAAkB,cAAE,UAAU,EAAC,GAAG;IACvC,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,wBAAgB;IAE5C,CAAA,GAAA,mBAAW,EAAE,MAAM,SAAS,EAAE,MAAM,WAAW,EAAE,MAAM,cAAc;IACrE,CAAA,GAAA,wBAAgB,EAAE;4BAChB;QACA,OAAO;gBAAM;oBAAA,sBAAA,WAAW,OAAO,cAAlB,0CAAA,oBAAoB,KAAK;;IACxC,GAAG,OAAO,MAAM,SAAS;QA0Bd;IAxBX,wFAAwF;IACxF,sFAAsF;IACtF,gDAAgD;IAChD,8FAA8F;IAC9F,kGAAkG;IAClG,mCAAmC;IACnC,OAAO;QACL,gBAAgB;YACd,GAAG,mBAAmB;YACtB,eAAe;YACf,aAAa;YACb,CAAC,gCAAgC,EAAE;YACnC,aAAa;YACb,CAAC,mBAAmB,EAAE;QACxB;QACA,YAAY;YACV,OAAO;gBAAC,SAAS;YAAM;QACzB;QACA,aAAa;YACX,UAAU;0BACV;YACA,UAAU;YACV,UAAU,uBAAuB,YAAY;kBAC7C;YACA,OAAO,CAAA,qBAAA,MAAM,WAAW,cAAjB,gCAAA,qBAAqB;YAC5B,UAAU,CAAC,IAA4C,MAAM,cAAc,CAAC,EAAE,MAAM,CAAC,KAAK;QAC5F;IACF;AACF;AAMO,SAAS,0CAAgB,KAA2B;IACzD,IAAI,SAAC,KAAK,cAAE,UAAU,SAAE,KAAK,QAAE,IAAI,cAAE,UAAU,EAAC,GAAG;IACnD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,kBAAC,cAAc,eAAE,WAAW,EAAC,GAAG,0CAAgB;QAAC,GAAG,KAAK;mBAAE;IAAS,GAAG,OAAO;QAmCrE;IAjCb,qFAAqF;IACrF,0FAA0F;IAC1F,+DAA+D;IAC/D,IAAI,MAAM,UAAU,CAAC,IAAI,IAAI,KAC3B,qBACE,gCAAC;QAAK,GAAG,cAAc;QAAE,eAAY;qBACnC,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,QAAQ,KAAK,IAAI,KAAK,QACxB,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/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 */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport React, {ReactNode, 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 {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 | null>\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n /** A ref to the hidden `<select>` element. */\n selectRef?: RefObject<HTMLSelectElement | null>\n}\n\nexport interface HiddenSelectAria {\n /** Props for the container element. */\n containerProps: React.HTMLAttributes<FocusableElement>,\n\n /** Props for the hidden input element. */\n inputProps: React.InputHTMLAttributes<HTMLInputElement>,\n\n /** Props for the hidden select element. */\n selectProps: React.SelectHTMLAttributes<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 | null>): HiddenSelectAria {\n let data = selectData.get(state) || {};\n let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\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 return {\n containerProps: {\n ...visuallyHiddenProps,\n 'aria-hidden': true,\n // @ts-ignore\n ['data-react-aria-prevent-focus']: true,\n // @ts-ignore\n ['data-a11y-ignore']: 'aria-hidden-focus'\n },\n inputProps: {\n style: {display: 'none'}\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, 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 <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 && 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":"HiddenSelect.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,
|
|
4
|
+
import { DOMAttributes, KeyboardDelegate, RefObject, ValidationResult, FocusableElement } from "@react-types/shared";
|
|
5
5
|
import { SelectState } from "@react-stately/select";
|
|
6
6
|
import React, { ReactNode } from "react";
|
|
7
7
|
export interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {
|
|
@@ -31,7 +31,7 @@ export interface SelectAria<T> extends ValidationResult {
|
|
|
31
31
|
* @param props - Props for the select.
|
|
32
32
|
* @param state - State for the select, as returned by `useListState`.
|
|
33
33
|
*/
|
|
34
|
-
export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<
|
|
34
|
+
export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<HTMLElement | null>): SelectAria<T>;
|
|
35
35
|
export interface AriaHiddenSelectProps {
|
|
36
36
|
/**
|
|
37
37
|
* 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).
|
|
@@ -72,7 +72,7 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
72
72
|
* Renders a hidden native `<select>` element, which can be used to support browser
|
|
73
73
|
* form autofill, mobile form navigation, and native form submission.
|
|
74
74
|
*/
|
|
75
|
-
export function HiddenSelect<T>(props: HiddenSelectProps<T>): React.JSX.Element;
|
|
75
|
+
export function HiddenSelect<T>(props: HiddenSelectProps<T>): React.JSX.Element | null;
|
|
76
76
|
export type { AriaSelectProps } from '@react-types/select';
|
|
77
77
|
|
|
78
78
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAyBA,mCAAmC,CAAC,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,CAAC;IAChF;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,4BAA4B,CAAC,CAAE,SAAQ,gBAAgB;IACrD,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAE1B,2CAA2C;IAC3C,YAAY,EAAE,eAAe,CAAC;IAE9B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAE1B,2BAA2B;IAC3B,SAAS,EAAE,mBAAmB,CAAC,CAAC,CAAC;IAEjC,0DAA0D;IAC1D,gBAAgB,EAAE,aAAa,CAAC;IAEhC,4DAA4D;IAC5D,iBAAiB,EAAE,aAAa,CAAA;CACjC;AAWD;;;;;GAKG;AACH,0BAA0B,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,
|
|
1
|
+
{"mappings":";;;;;;AAyBA,mCAAmC,CAAC,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,CAAC;IAChF;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,4BAA4B,CAAC,CAAE,SAAQ,gBAAgB;IACrD,mCAAmC;IACnC,UAAU,EAAE,aAAa,CAAC;IAE1B,2CAA2C;IAC3C,YAAY,EAAE,eAAe,CAAC;IAE9B,6DAA6D;IAC7D,UAAU,EAAE,aAAa,CAAC;IAE1B,2BAA2B;IAC3B,SAAS,EAAE,mBAAmB,CAAC,CAAC,C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,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,4BA2C1D;AC3ID,YAAY,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/select/src/packages/@react-aria/select/src/useSelect.ts","packages/@react-aria/select/src/packages/@react-aria/select/src/HiddenSelect.tsx","packages/@react-aria/select/src/packages/@react-aria/select/src/index.ts","packages/@react-aria/select/src/index.ts"],"sourcesContent":[null,null,null,"/*\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":"types.d.ts.map"}
|
package/dist/useSelect.main.js
CHANGED
|
@@ -39,7 +39,7 @@ function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
|
|
|
39
39
|
usage: 'search',
|
|
40
40
|
sensitivity: 'base'
|
|
41
41
|
});
|
|
42
|
-
let delegate = (0, $63cuq$react.useMemo)(()=>keyboardDelegate || new (0, $63cuq$reactariaselection.ListKeyboardDelegate)(state.collection, state.disabledKeys,
|
|
42
|
+
let delegate = (0, $63cuq$react.useMemo)(()=>keyboardDelegate || new (0, $63cuq$reactariaselection.ListKeyboardDelegate)(state.collection, state.disabledKeys, ref, collator), [
|
|
43
43
|
keyboardDelegate,
|
|
44
44
|
state.collection,
|
|
45
45
|
state.disabledKeys,
|
|
@@ -53,17 +53,19 @@ function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
|
|
|
53
53
|
switch(e.key){
|
|
54
54
|
case 'ArrowLeft':
|
|
55
55
|
{
|
|
56
|
+
var _delegate_getKeyAbove, _delegate_getFirstKey;
|
|
56
57
|
// prevent scrolling containers
|
|
57
58
|
e.preventDefault();
|
|
58
|
-
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
59
|
+
let key = state.selectedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, state.selectedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
|
|
59
60
|
if (key) state.setSelectedKey(key);
|
|
60
61
|
break;
|
|
61
62
|
}
|
|
62
63
|
case 'ArrowRight':
|
|
63
64
|
{
|
|
65
|
+
var _delegate_getKeyBelow, _delegate_getFirstKey1;
|
|
64
66
|
// prevent scrolling containers
|
|
65
67
|
e.preventDefault();
|
|
66
|
-
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
68
|
+
let key = state.selectedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, state.selectedKey) : (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate);
|
|
67
69
|
if (key) state.setSelectedKey(key);
|
|
68
70
|
break;
|
|
69
71
|
}
|
|
@@ -101,7 +103,8 @@ function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
|
|
|
101
103
|
...labelProps,
|
|
102
104
|
onClick: ()=>{
|
|
103
105
|
if (!props.isDisabled) {
|
|
104
|
-
|
|
106
|
+
var _ref_current;
|
|
107
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
105
108
|
// Show the focus ring so the user knows where focus went
|
|
106
109
|
(0, $63cuq$reactariainteractions.setInteractionModality)('keyboard');
|
|
107
110
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAuC;IACtH,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,GAAA,mCAAa,EAC/C;oBACE;QACA,MAAM;IACR,GACA,OACA;IAGF,IAAI,YAAY,CAAC;QACf,OAAQ,EAAE,GAAG;YACX,KAAK;gBAAa;oBAChB,+BAA+B;oBAC/B,EAAE,cAAc;oBAEhB,IAAI,MAAM,MAAM,WAAW,IAAI,OAAO,SAAS,WAAW,CAAC,MAAM,WAAW,IAAI,SAAS,WAAW;oBACpG,IAAI,KACF,MAAM,cAAc,CAAC;oBAEvB;gBACF;YACA,KAAK;gBAAc;oBACjB,+BAA+B;oBAC/B,EAAE,cAAc;oBAEhB,IAAI,MAAM,MAAM,WAAW,IAAI,OAAO,SAAS,WAAW,CAAC,MAAM,WAAW,IAAI,SAAS,WAAW;oBACpG,IAAI,KACF,MAAM,cAAc,CAAC;oBAE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AAM,CAAC,SAAS,IAAI,CAAC;YACvB,SAAQ,CAAa;gBACnB,IAAI,MAAM,SAAS,EACjB;gBAGF,IAAI,MAAM,OAAO,EACf,MAAM,OAAO,CAAC;gBAGhB,IAAI,MAAM,aAAa,EACrB,MAAM,aAAa,CAAC;gBAGtB,MAAM,UAAU,CAAC;YACnB;YACA,QAAO,CAAa;gBAClB,IAAI,MAAM,MAAM,EACd;gBAGF,IAAI,MAAM,MAAM,EACd,MAAM,MAAM,CAAC;gBAGf,IAAI,MAAM,aAAa,EACrB,MAAM,aAAa,CAAC;gBAGtB,MAAM,UAAU,CAAC;YACnB;QACF;QACA,YAAY;YACV,IAAI;QACN;QACA,WAAW;YACT,GAAG,SAAS;YACZ,WAAW,MAAM,aAAa,IAAI;YAClC,uBAAuB;YACvB,oBAAoB;YACpB,wBAAwB;YACxB,cAAc;YACd,QAAQ,CAAC;gBACP,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,aAAa,GAC1C;gBAGF,IAAI,MAAM,MAAM,EACd,MAAM,MAAM,CAAC;gBAGf,IAAI,MAAM,aAAa,EACrB,MAAM,aAAa,CAAC;gBAGtB,MAAM,UAAU,CAAC;YACnB;YACA,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, RefObject, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, 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 | null>): 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"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAkC;IACjH,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,sBACJ,qBAAqB,QACtB,GAAG;IAEJ,0HAA0H;IAC1H,qF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AAM,MAAM,EACd;gBAGF,IAAI,MAAM,MAAM,EACd,MAAM,MAAM,CAAC;gBAGf,IAAI,MAAM,aAAa,EACrB,MAAM,aAAa,CAAC;gBAGtB,MAAM,UAAU,CAAC;YACnB;QACF;QACA,YAAY;YACV,IAAI;QACN;QACA,WAAW;YACT,GAAG,SAAS;YACZ,WAAW,MAAM,aAAa,IAAI;YAClC,uBAAuB;YACvB,oBAAoB;YACpB,wBAAwB;YACxB,cAAc;YACd,QAAQ,CAAC;gBACP,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,aAAa,GAC1C;gBAGF,IAAI,MAAM,MAAM,EACd,MAAM,MAAM,CAAC;gBAGf,IAAI,MAAM,aAAa,EACrB,MAAM,aAAa,CAAC;gBAGtB,MAAM,UAAU,CAAC;YACnB;YACA,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, KeyboardDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, 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<HTMLElement | null>): 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, ref, 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"}
|
package/dist/useSelect.mjs
CHANGED
|
@@ -32,7 +32,7 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
32
32
|
usage: 'search',
|
|
33
33
|
sensitivity: 'base'
|
|
34
34
|
});
|
|
35
|
-
let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys,
|
|
35
|
+
let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys, ref, collator), [
|
|
36
36
|
keyboardDelegate,
|
|
37
37
|
state.collection,
|
|
38
38
|
state.disabledKeys,
|
|
@@ -46,17 +46,19 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
46
46
|
switch(e.key){
|
|
47
47
|
case 'ArrowLeft':
|
|
48
48
|
{
|
|
49
|
+
var _delegate_getKeyAbove, _delegate_getFirstKey;
|
|
49
50
|
// prevent scrolling containers
|
|
50
51
|
e.preventDefault();
|
|
51
|
-
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
52
|
+
let key = state.selectedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, state.selectedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
|
|
52
53
|
if (key) state.setSelectedKey(key);
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
56
|
case 'ArrowRight':
|
|
56
57
|
{
|
|
58
|
+
var _delegate_getKeyBelow, _delegate_getFirstKey1;
|
|
57
59
|
// prevent scrolling containers
|
|
58
60
|
e.preventDefault();
|
|
59
|
-
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
61
|
+
let key = state.selectedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, state.selectedKey) : (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate);
|
|
60
62
|
if (key) state.setSelectedKey(key);
|
|
61
63
|
break;
|
|
62
64
|
}
|
|
@@ -94,7 +96,8 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
94
96
|
...labelProps,
|
|
95
97
|
onClick: ()=>{
|
|
96
98
|
if (!props.isDisabled) {
|
|
97
|
-
|
|
99
|
+
var _ref_current;
|
|
100
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
98
101
|
// Show the focus ring so the user knows where focus went
|
|
99
102
|
(0, $aUnai$setInteractionModality)('keyboard');
|
|
100
103
|
}
|
package/dist/useSelect.module.js
CHANGED
|
@@ -32,7 +32,7 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
32
32
|
usage: 'search',
|
|
33
33
|
sensitivity: 'base'
|
|
34
34
|
});
|
|
35
|
-
let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys,
|
|
35
|
+
let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys, ref, collator), [
|
|
36
36
|
keyboardDelegate,
|
|
37
37
|
state.collection,
|
|
38
38
|
state.disabledKeys,
|
|
@@ -46,17 +46,19 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
46
46
|
switch(e.key){
|
|
47
47
|
case 'ArrowLeft':
|
|
48
48
|
{
|
|
49
|
+
var _delegate_getKeyAbove, _delegate_getFirstKey;
|
|
49
50
|
// prevent scrolling containers
|
|
50
51
|
e.preventDefault();
|
|
51
|
-
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
52
|
+
let key = state.selectedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, state.selectedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
|
|
52
53
|
if (key) state.setSelectedKey(key);
|
|
53
54
|
break;
|
|
54
55
|
}
|
|
55
56
|
case 'ArrowRight':
|
|
56
57
|
{
|
|
58
|
+
var _delegate_getKeyBelow, _delegate_getFirstKey1;
|
|
57
59
|
// prevent scrolling containers
|
|
58
60
|
e.preventDefault();
|
|
59
|
-
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
61
|
+
let key = state.selectedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, state.selectedKey) : (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate);
|
|
60
62
|
if (key) state.setSelectedKey(key);
|
|
61
63
|
break;
|
|
62
64
|
}
|
|
@@ -94,7 +96,8 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
|
|
|
94
96
|
...labelProps,
|
|
95
97
|
onClick: ()=>{
|
|
96
98
|
if (!props.isDisabled) {
|
|
97
|
-
|
|
99
|
+
var _ref_current;
|
|
100
|
+
(_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
|
|
98
101
|
// Show the focus ring so the user knows where focus went
|
|
99
102
|
(0, $aUnai$setInteractionModality)('keyboard');
|
|
100
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAuC;IACtH,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,sBACJ,qBAAqB,QACtB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,oBAAoB,IAAI,CAAA,GAAA,2BAAmB,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,GAAA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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, RefObject, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, 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 | null>): 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.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAkC;IACjH,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,sBACJ,qBAAqB,QACtB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,oBAAoB,IAAI,CAAA,GAAA,2BAAmB,EAAE,MAAM,UAAU,EAAE,MAAM,YAAY,EAAE,KAAK,WAAW;QAAC;QAAkB,MAAM,UAAU;QAAE,MAAM,YAAY;QAAE;KAAS;IAElM,IAAI,oBAAC,gBAAgB,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qBAAa,EAC/C;oBACE;QACA,MAAM;IACR,GACA,OACA;IAGF,IAAI,YAAY,CAAC;QACf,OAAQ,EAAE,GAAG;YACX,KAAK;gBAAa;wBAIsB,uBAA4C;oBAHlF,+BAA+B;oBAC/B,EAAE,cAAc;oBAEhB,IAAI,MAAM,MAAM,WAAW,IAAI,QAAO,wBAAA,SAAS,WAAW,cAApB,4CAAA,2BAAA,UAAuB,MAAM,WAAW,KAAI,wBAAA,SAAS,WAAW,cAApB,4CAAA,2BAAA;oBAClF,IAAI,KACF,MAAM,cAAc,CAAC;oBAEvB;gBACF;YACA,KAAK;gBAAc;wBAIqB,uBAA4C;oBAHlF,+BAA+B;oBAC/B,EA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 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, KeyboardDelegate, RefObject, ValidationResult} from '@react-types/shared';\nimport {FocusEvent, 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<HTMLElement | null>): 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, ref, 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.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/select",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.15.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,26 +22,27 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/form": "^3.0.
|
|
26
|
-
"@react-aria/i18n": "^3.12.
|
|
27
|
-
"@react-aria/interactions": "^3.22.
|
|
28
|
-
"@react-aria/label": "^3.7.
|
|
29
|
-
"@react-aria/listbox": "^3.13.
|
|
30
|
-
"@react-aria/menu": "^3.
|
|
31
|
-
"@react-aria/selection": "^3.
|
|
32
|
-
"@react-aria/utils": "^3.
|
|
33
|
-
"@react-aria/visually-hidden": "^3.8.
|
|
34
|
-
"@react-stately/select": "^3.6.
|
|
35
|
-
"@react-types/button": "^3.10.
|
|
36
|
-
"@react-types/select": "^3.9.
|
|
37
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/form": "^3.0.11",
|
|
26
|
+
"@react-aria/i18n": "^3.12.4",
|
|
27
|
+
"@react-aria/interactions": "^3.22.5",
|
|
28
|
+
"@react-aria/label": "^3.7.13",
|
|
29
|
+
"@react-aria/listbox": "^3.13.6",
|
|
30
|
+
"@react-aria/menu": "^3.16.0",
|
|
31
|
+
"@react-aria/selection": "^3.21.0",
|
|
32
|
+
"@react-aria/utils": "^3.26.0",
|
|
33
|
+
"@react-aria/visually-hidden": "^3.8.18",
|
|
34
|
+
"@react-stately/select": "^3.6.9",
|
|
35
|
+
"@react-types/button": "^3.10.1",
|
|
36
|
+
"@react-types/select": "^3.9.8",
|
|
37
|
+
"@react-types/shared": "^3.26.0",
|
|
38
38
|
"@swc/helpers": "^0.5.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
|
|
42
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
41
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
42
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
|
46
|
-
}
|
|
47
|
-
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
|
|
48
|
+
}
|
package/src/HiddenSelect.tsx
CHANGED
|
@@ -16,7 +16,6 @@ import {selectData} from './useSelect';
|
|
|
16
16
|
import {SelectState} from '@react-stately/select';
|
|
17
17
|
import {useFormReset} from '@react-aria/utils';
|
|
18
18
|
import {useFormValidation} from '@react-aria/form';
|
|
19
|
-
import {useInteractionModality} from '@react-aria/interactions';
|
|
20
19
|
import {useVisuallyHidden} from '@react-aria/visually-hidden';
|
|
21
20
|
|
|
22
21
|
export interface AriaHiddenSelectProps {
|
|
@@ -68,13 +67,12 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
68
67
|
let data = selectData.get(state) || {};
|
|
69
68
|
let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;
|
|
70
69
|
let {validationBehavior, isRequired} = data;
|
|
71
|
-
let modality = useInteractionModality();
|
|
72
70
|
let {visuallyHiddenProps} = useVisuallyHidden();
|
|
73
71
|
|
|
74
72
|
useFormReset(props.selectRef, state.selectedKey, state.setSelectedKey);
|
|
75
73
|
useFormValidation({
|
|
76
74
|
validationBehavior,
|
|
77
|
-
focus: () => triggerRef.current
|
|
75
|
+
focus: () => triggerRef.current?.focus()
|
|
78
76
|
}, state, props.selectRef);
|
|
79
77
|
|
|
80
78
|
// In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
|
|
@@ -83,18 +81,6 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
83
81
|
// The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
|
|
84
82
|
// 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
|
|
85
83
|
// non tabbable with tabIndex={-1}.
|
|
86
|
-
//
|
|
87
|
-
// In mobile browsers, there are next/previous buttons above the software keyboard for navigating
|
|
88
|
-
// between fields in a form. These only support native form inputs that are tabbable. In order to
|
|
89
|
-
// support those, an additional hidden input is used to marshall focus to the button. It is tabbable
|
|
90
|
-
// except when the button is focused, so that shift tab works properly to go to the actual previous
|
|
91
|
-
// input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes
|
|
92
|
-
// the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to
|
|
93
|
-
// prevent Safari from zooming in on the input when it is focused.
|
|
94
|
-
//
|
|
95
|
-
// If the current interaction modality is null, then the user hasn't interacted with the page yet.
|
|
96
|
-
// In this case, we set the tabIndex to -1 on the input element so that automated accessibility
|
|
97
|
-
// checkers don't throw false-positives about focusable elements inside an aria-hidden parent.
|
|
98
84
|
return {
|
|
99
85
|
containerProps: {
|
|
100
86
|
...visuallyHiddenProps,
|
|
@@ -105,11 +91,7 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
105
91
|
['data-a11y-ignore']: 'aria-hidden-focus'
|
|
106
92
|
},
|
|
107
93
|
inputProps: {
|
|
108
|
-
|
|
109
|
-
tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
|
|
110
|
-
style: {fontSize: 16},
|
|
111
|
-
onFocus: () => triggerRef.current.focus(),
|
|
112
|
-
disabled: isDisabled
|
|
94
|
+
style: {display: 'none'}
|
|
113
95
|
},
|
|
114
96
|
selectProps: {
|
|
115
97
|
tabIndex: -1,
|
|
@@ -130,7 +112,7 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
|
|
|
130
112
|
export function HiddenSelect<T>(props: HiddenSelectProps<T>) {
|
|
131
113
|
let {state, triggerRef, label, name, isDisabled} = props;
|
|
132
114
|
let selectRef = useRef(null);
|
|
133
|
-
let {containerProps,
|
|
115
|
+
let {containerProps, selectProps} = useHiddenSelect({...props, selectRef}, state, triggerRef);
|
|
134
116
|
|
|
135
117
|
// If used in a <form>, use a hidden input so the value can be submitted to a server.
|
|
136
118
|
// If the collection isn't too big, use a hidden <select> element for this so that browser
|
|
@@ -138,14 +120,13 @@ export function HiddenSelect<T>(props: HiddenSelectProps<T>) {
|
|
|
138
120
|
if (state.collection.size <= 300) {
|
|
139
121
|
return (
|
|
140
122
|
<div {...containerProps} data-testid="hidden-select-container">
|
|
141
|
-
<input {...inputProps} />
|
|
142
123
|
<label>
|
|
143
124
|
{label}
|
|
144
125
|
<select {...selectProps} ref={selectRef}>
|
|
145
126
|
<option />
|
|
146
127
|
{[...state.collection.getKeys()].map(key => {
|
|
147
128
|
let item = state.collection.getItem(key);
|
|
148
|
-
if (item.type === 'item') {
|
|
129
|
+
if (item && item.type === 'item') {
|
|
149
130
|
return (
|
|
150
131
|
<option
|
|
151
132
|
key={item.key}
|
package/src/useSelect.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {AriaButtonProps} from '@react-types/button';
|
|
|
14
14
|
import {AriaListBoxOptions} from '@react-aria/listbox';
|
|
15
15
|
import {AriaSelectProps} from '@react-types/select';
|
|
16
16
|
import {chain, filterDOMProps, mergeProps, useId} from '@react-aria/utils';
|
|
17
|
-
import {DOMAttributes,
|
|
17
|
+
import {DOMAttributes, KeyboardDelegate, RefObject, ValidationResult} from '@react-types/shared';
|
|
18
18
|
import {FocusEvent, useMemo} from 'react';
|
|
19
19
|
import {ListKeyboardDelegate, useTypeSelect} from '@react-aria/selection';
|
|
20
20
|
import {SelectState} from '@react-stately/select';
|
|
@@ -66,7 +66,7 @@ export const selectData = new WeakMap<SelectState<any>, SelectData>();
|
|
|
66
66
|
* @param props - Props for the select.
|
|
67
67
|
* @param state - State for the select, as returned by `useListState`.
|
|
68
68
|
*/
|
|
69
|
-
export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<
|
|
69
|
+
export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<HTMLElement | null>): SelectAria<T> {
|
|
70
70
|
let {
|
|
71
71
|
keyboardDelegate,
|
|
72
72
|
isDisabled,
|
|
@@ -78,7 +78,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
|
|
|
78
78
|
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
79
79
|
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
80
80
|
let collator = useCollator({usage: 'search', sensitivity: 'base'});
|
|
81
|
-
let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(state.collection, state.disabledKeys,
|
|
81
|
+
let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(state.collection, state.disabledKeys, ref, collator), [keyboardDelegate, state.collection, state.disabledKeys, collator]);
|
|
82
82
|
|
|
83
83
|
let {menuTriggerProps, menuProps} = useMenuTrigger<T>(
|
|
84
84
|
{
|
|
@@ -95,7 +95,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
|
|
|
95
95
|
// prevent scrolling containers
|
|
96
96
|
e.preventDefault();
|
|
97
97
|
|
|
98
|
-
let key = state.selectedKey != null ? delegate.getKeyAbove(state.selectedKey) : delegate.getFirstKey();
|
|
98
|
+
let key = state.selectedKey != null ? delegate.getKeyAbove?.(state.selectedKey) : delegate.getFirstKey?.();
|
|
99
99
|
if (key) {
|
|
100
100
|
state.setSelectedKey(key);
|
|
101
101
|
}
|
|
@@ -105,7 +105,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
|
|
|
105
105
|
// prevent scrolling containers
|
|
106
106
|
e.preventDefault();
|
|
107
107
|
|
|
108
|
-
let key = state.selectedKey != null ? delegate.getKeyBelow(state.selectedKey) : delegate.getFirstKey();
|
|
108
|
+
let key = state.selectedKey != null ? delegate.getKeyBelow?.(state.selectedKey) : delegate.getFirstKey?.();
|
|
109
109
|
if (key) {
|
|
110
110
|
state.setSelectedKey(key);
|
|
111
111
|
}
|
|
@@ -150,7 +150,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
|
|
|
150
150
|
...labelProps,
|
|
151
151
|
onClick: () => {
|
|
152
152
|
if (!props.isDisabled) {
|
|
153
|
-
ref.current
|
|
153
|
+
ref.current?.focus();
|
|
154
154
|
|
|
155
155
|
// Show the focus ring so the user knows where focus went
|
|
156
156
|
setInteractionModality('keyboard');
|