@react-aria/select 3.14.11 → 3.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/HiddenSelect.main.js +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 +17 -17
- package/src/HiddenSelect.tsx +4 -23
- package/src/useSelect.ts +6 -6
|
@@ -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,CAAA,GAAA,sCAAgB,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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.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":";;;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,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,EAA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ACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,qCAAqC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,mCAAmC,CAAC,CAAE,SAAQ,qBAAqB;IACjE,4BAA4B;IAC5B,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAEtB,oCAAoC;IACpC,UAAU,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,CAAA;CAC/C;AAED,iCAAyC,SAAQ,qBAAqB;IACpE,8CAA8C;IAC9C,SAAS,CAAC,EAAE,UAAU,iBAAiB,GAAG,IAAI,CAAC,CAAA;CAChD;AAED;IACE,uCAAuC;IACvC,cAAc,EAAE,MAAM,cAAc,CAAC,gBAAgB,CAAC,CAAC;IAEvD,0CAA0C;IAC1C,UAAU,EAAE,MAAM,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAExD,2CAA2C;IAC3C,WAAW,EAAE,MAAM,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;CAC3D;AAED;;;;GAIG;AACH,gCAAgC,CAAC,EAAE,KAAK,EAAE,uBAAuB,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAwC1J;AAED;;;GAGG;AACH,6BAA6B,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,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AAM,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,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,KAAK,WAAW;QAAC;QAAkB,MAAM,UAAU;QAAE,MAAM,YAAY;QAAE;KAAS;IAElM,IAAI,oBAAC,gBAAgB,aAAE,SAAS,EAAC,G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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,qBAAa,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,+B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MAAM,OAAO;YACtB,mBAAmB;gBACjB;gBACA,YAAY,CAAC,kBAAkB;gBAC/B,YAAY,CAAC,aAAa,IAAI,CAAC,YAAY,CAAC,kBAAkB,GAAG,aAAa,EAAE,GAAG;aACpF,CAAC,MAAM,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.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAkDM,MAAM,4CAAa,IAAI;AAQvB,SAAS,0CAAa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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, 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.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,27 +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.
|
|
28
|
-
"@react-aria/label": "^3.7.
|
|
29
|
-
"@react-aria/listbox": "^3.
|
|
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.12",
|
|
26
|
+
"@react-aria/i18n": "^3.12.5",
|
|
27
|
+
"@react-aria/interactions": "^3.23.0",
|
|
28
|
+
"@react-aria/label": "^3.7.14",
|
|
29
|
+
"@react-aria/listbox": "^3.14.0",
|
|
30
|
+
"@react-aria/menu": "^3.17.0",
|
|
31
|
+
"@react-aria/selection": "^3.22.0",
|
|
32
|
+
"@react-aria/utils": "^3.27.0",
|
|
33
|
+
"@react-aria/visually-hidden": "^3.8.19",
|
|
34
|
+
"@react-stately/select": "^3.6.10",
|
|
35
|
+
"@react-types/button": "^3.10.2",
|
|
36
|
+
"@react-types/select": "^3.9.9",
|
|
37
|
+
"@react-types/shared": "^3.27.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
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
|
|
48
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');
|