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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ var $23a1e93dc7fa8653$exports = require("./useSelect.main.js");
2
+ var $ccxQv$react = require("react");
3
+ var $ccxQv$reactariautils = require("@react-aria/utils");
4
+ var $ccxQv$reactariaform = require("@react-aria/form");
5
+ var $ccxQv$reactariainteractions = require("@react-aria/interactions");
6
+ var $ccxQv$reactariavisuallyhidden = require("@react-aria/visually-hidden");
7
+
8
+
9
+ function $parcel$interopDefault(a) {
10
+ return a && a.__esModule ? a.default : a;
11
+ }
12
+
13
+ function $parcel$export(e, n, v, s) {
14
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
15
+ }
16
+
17
+ $parcel$export(module.exports, "useHiddenSelect", () => $6eae0e0872a4cdd4$export$f809e80f58e251d1);
18
+ $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$export$cbd84cdb2e668835);
19
+ /*
20
+ * Copyright 2020 Adobe. All rights reserved.
21
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
22
+ * you may not use this file except in compliance with the License. You may obtain a copy
23
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software distributed under
26
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
27
+ * OF ANY KIND, either express or implied. See the License for the specific language
28
+ * governing permissions and limitations under the License.
29
+ */
30
+
31
+
32
+
33
+
34
+
35
+ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
36
+ let data = (0, $23a1e93dc7fa8653$exports.selectData).get(state) || {};
37
+ let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
38
+ let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
39
+ let modality = (0, $ccxQv$reactariainteractions.useInteractionModality)();
40
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $ccxQv$reactariavisuallyhidden.useVisuallyHidden)();
41
+ (0, $ccxQv$reactariautils.useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
42
+ (0, $ccxQv$reactariaform.useFormValidation)({
43
+ validationBehavior: validationBehavior,
44
+ focus: ()=>triggerRef.current.focus()
45
+ }, state, props.selectRef);
46
+ var _state_selectedKey;
47
+ // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
48
+ // In Firefox, there must be a <label> to identify the <select> whereas other browsers
49
+ // seem to identify it just by surrounding text.
50
+ // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
51
+ // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
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
+ return {
66
+ containerProps: {
67
+ ...visuallyHiddenProps,
68
+ "aria-hidden": true,
69
+ ["data-hidden-select-ignore"]: true,
70
+ ["data-a11y-ignore"]: "aria-hidden-focus"
71
+ },
72
+ inputProps: {
73
+ type: "text",
74
+ tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
75
+ style: {
76
+ fontSize: 16
77
+ },
78
+ onFocus: ()=>triggerRef.current.focus(),
79
+ disabled: isDisabled
80
+ },
81
+ selectProps: {
82
+ tabIndex: -1,
83
+ autoComplete: autoComplete,
84
+ disabled: isDisabled,
85
+ required: validationBehavior === "native" && isRequired,
86
+ name: name,
87
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : "",
88
+ onChange: (e)=>state.setSelectedKey(e.target.value)
89
+ }
90
+ };
91
+ }
92
+ function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
93
+ let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
94
+ let selectRef = (0, $ccxQv$react.useRef)(null);
95
+ let { containerProps: containerProps, inputProps: inputProps, selectProps: selectProps } = $6eae0e0872a4cdd4$export$f809e80f58e251d1({
96
+ ...props,
97
+ selectRef: selectRef
98
+ }, state, triggerRef);
99
+ var _state_selectedKey;
100
+ // If used in a <form>, use a hidden input so the value can be submitted to a server.
101
+ // If the collection isn't too big, use a hidden <select> element for this so that browser
102
+ // autofill will work. Otherwise, use an <input type="hidden">.
103
+ if (state.collection.size <= 300) return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("div", {
104
+ ...containerProps,
105
+ "data-testid": "hidden-select-container"
106
+ }, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("input", inputProps), /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("label", null, label, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("select", {
107
+ ...selectProps,
108
+ ref: selectRef
109
+ }, /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("option", null), [
110
+ ...state.collection.getKeys()
111
+ ].map((key)=>{
112
+ let item = state.collection.getItem(key);
113
+ if (item.type === "item") return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("option", {
114
+ key: item.key,
115
+ value: item.key
116
+ }, item.textValue);
117
+ }))));
118
+ else if (name) return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("input", {
119
+ type: "hidden",
120
+ autoComplete: selectProps.autoComplete,
121
+ name: name,
122
+ disabled: isDisabled,
123
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ""
124
+ });
125
+ return null;
126
+ }
127
+
128
+
129
+ //# sourceMappingURL=HiddenSelect.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6CM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAAuC;IAC/H,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,WAAW,CAAA,GAAA,mDAAqB;IACpC,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,IAAM,WAAW,OAAO,CAAC,KAAK;IACvC,GAAG,OAAO,MAAM,SAAS;QAwCd;IAtCX,wFAAwF;IACxF,sFAAsF;IACtF,gDAAgD;IAChD,8FAA8F;IAC9F,kGAAkG;IAClG,mCAAmC;IACnC,EAAE;IACF,iGAAiG;IACjG,iGAAiG;IACjG,oGAAoG;IACpG,mGAAmG;IACnG,+FAA+F;IAC/F,+FAA+F;IAC/F,kEAAkE;IAClE,EAAE;IACF,kGAAkG;IAClG,+FAA+F;IAC/F,8FAA8F;IAC9F,OAAO;QACL,gBAAgB;YACd,GAAG,mBAAmB;YACtB,eAAe;YACf,CAAC,4BAA4B,EAAE;YAC/B,CAAC,mBAAmB,EAAE;QACxB;QACA,YAAY;YACV,MAAM;YACN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AM,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} from '@react-types/shared';\nimport React, {ReactNode, RefObject, useRef} from 'react';\nimport {selectData} from './useSelect';\nimport {SelectState} from '@react-stately/select';\nimport {useFormReset} from '@react-aria/utils';\nimport {useFormValidation} from '@react-aria/form';\nimport {useInteractionModality} from '@react-aria/interactions';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaHiddenSelectProps {\n /**\n * Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).\n */\n autoComplete?: string,\n\n /** The text label for the select. */\n label?: ReactNode,\n\n /** HTML form input name. */\n name?: string,\n\n /** Sets the disabled state of the select and input. */\n isDisabled?: boolean\n}\n\nexport interface HiddenSelectProps<T> extends AriaHiddenSelectProps {\n /** State for the select. */\n state: SelectState<T>,\n\n /** A ref to the trigger element. */\n triggerRef: RefObject<FocusableElement>\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n /** A ref to the hidden `<select>` element. */\n selectRef?: RefObject<HTMLSelectElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a hidden `<select>` element, which\n * can be used in combination with `useSelect` to support browser form autofill, mobile form\n * navigation, and native HTML form submission.\n */\nexport function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: SelectState<T>, triggerRef: RefObject<FocusableElement>) {\n let data = selectData.get(state) || {};\n let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\n let modality = useInteractionModality();\n let {visuallyHiddenProps} = useVisuallyHidden();\n\n useFormReset(props.selectRef, state.selectedKey, state.setSelectedKey);\n useFormValidation({\n validationBehavior,\n focus: () => triggerRef.current.focus()\n }, state, props.selectRef);\n\n // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.\n // In Firefox, there must be a <label> to identify the <select> whereas other browsers\n // seem to identify it just by surrounding text.\n // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a\n // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>\n // non tabbable with tabIndex={-1}.\n //\n // In mobile browsers, there are next/previous buttons above the software keyboard for navigating\n // between fields in a form. These only support native form inputs that are tabbable. In order to\n // support those, an additional hidden input is used to marshall focus to the button. It is tabbable\n // except when the button is focused, so that shift tab works properly to go to the actual previous\n // input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes\n // the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to\n // prevent Safari from zooming in on the input when it is focused.\n //\n // If the current interaction modality is null, then the user hasn't interacted with the page yet.\n // In this case, we set the tabIndex to -1 on the input element so that automated accessibility\n // checkers don't throw false-positives about focusable elements inside an aria-hidden parent.\n return {\n containerProps: {\n ...visuallyHiddenProps,\n 'aria-hidden': true,\n ['data-hidden-select-ignore']: true,\n ['data-a11y-ignore']: 'aria-hidden-focus'\n },\n inputProps: {\n type: 'text',\n tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,\n style: {fontSize: 16},\n onFocus: () => triggerRef.current.focus(),\n disabled: isDisabled\n },\n selectProps: {\n tabIndex: -1,\n autoComplete,\n disabled: isDisabled,\n required: validationBehavior === 'native' && isRequired,\n name,\n value: state.selectedKey ?? '',\n onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value)\n }\n };\n}\n\n/**\n * Renders a hidden native `<select>` element, which can be used to support browser\n * form autofill, mobile form navigation, and native form submission.\n */\nexport function HiddenSelect<T>(props: HiddenSelectProps<T>) {\n let {state, triggerRef, label, name, isDisabled} = props;\n let selectRef = useRef(null);\n let {containerProps, inputProps, selectProps} = useHiddenSelect({...props, selectRef}, state, triggerRef);\n\n // If used in a <form>, use a hidden input so the value can be submitted to a server.\n // If the collection isn't too big, use a hidden <select> element for this so that browser\n // autofill will work. Otherwise, use an <input type=\"hidden\">.\n if (state.collection.size <= 300) {\n return (\n <div {...containerProps} data-testid=\"hidden-select-container\">\n <input {...inputProps} />\n <label>\n {label}\n <select {...selectProps} ref={selectRef}>\n <option />\n {[...state.collection.getKeys()].map(key => {\n let item = state.collection.getItem(key);\n if (item.type === 'item') {\n return (\n <option\n key={item.key}\n value={item.key}>\n {item.textValue}\n </option>\n );\n }\n })}\n </select>\n </label>\n </div>\n );\n } else if (name) {\n return (\n <input\n type=\"hidden\"\n autoComplete={selectProps.autoComplete}\n name={name}\n disabled={isDisabled}\n value={state.selectedKey ?? ''} />\n );\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"HiddenSelect.main.js.map"}
@@ -0,0 +1,119 @@
1
+ import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSelect.mjs";
2
+ import $8BE50$react, {useRef as $8BE50$useRef} from "react";
3
+ import {useFormReset as $8BE50$useFormReset} from "@react-aria/utils";
4
+ import {useFormValidation as $8BE50$useFormValidation} from "@react-aria/form";
5
+ import {useInteractionModality as $8BE50$useInteractionModality} from "@react-aria/interactions";
6
+ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
25
+ let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
26
+ let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
27
+ let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
28
+ let modality = (0, $8BE50$useInteractionModality)();
29
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
30
+ (0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
31
+ (0, $8BE50$useFormValidation)({
32
+ validationBehavior: validationBehavior,
33
+ focus: ()=>triggerRef.current.focus()
34
+ }, state, props.selectRef);
35
+ var _state_selectedKey;
36
+ // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
37
+ // In Firefox, there must be a <label> to identify the <select> whereas other browsers
38
+ // seem to identify it just by surrounding text.
39
+ // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
40
+ // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
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
+ return {
55
+ containerProps: {
56
+ ...visuallyHiddenProps,
57
+ "aria-hidden": true,
58
+ ["data-hidden-select-ignore"]: true,
59
+ ["data-a11y-ignore"]: "aria-hidden-focus"
60
+ },
61
+ inputProps: {
62
+ type: "text",
63
+ tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
64
+ style: {
65
+ fontSize: 16
66
+ },
67
+ onFocus: ()=>triggerRef.current.focus(),
68
+ disabled: isDisabled
69
+ },
70
+ selectProps: {
71
+ tabIndex: -1,
72
+ autoComplete: autoComplete,
73
+ disabled: isDisabled,
74
+ required: validationBehavior === "native" && isRequired,
75
+ name: name,
76
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : "",
77
+ onChange: (e)=>state.setSelectedKey(e.target.value)
78
+ }
79
+ };
80
+ }
81
+ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
82
+ let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
83
+ let selectRef = (0, $8BE50$useRef)(null);
84
+ let { containerProps: containerProps, inputProps: inputProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
85
+ ...props,
86
+ selectRef: selectRef
87
+ }, state, triggerRef);
88
+ var _state_selectedKey;
89
+ // If used in a <form>, use a hidden input so the value can be submitted to a server.
90
+ // If the collection isn't too big, use a hidden <select> element for this so that browser
91
+ // autofill will work. Otherwise, use an <input type="hidden">.
92
+ if (state.collection.size <= 300) return /*#__PURE__*/ (0, $8BE50$react).createElement("div", {
93
+ ...containerProps,
94
+ "data-testid": "hidden-select-container"
95
+ }, /*#__PURE__*/ (0, $8BE50$react).createElement("input", inputProps), /*#__PURE__*/ (0, $8BE50$react).createElement("label", null, label, /*#__PURE__*/ (0, $8BE50$react).createElement("select", {
96
+ ...selectProps,
97
+ ref: selectRef
98
+ }, /*#__PURE__*/ (0, $8BE50$react).createElement("option", null), [
99
+ ...state.collection.getKeys()
100
+ ].map((key)=>{
101
+ let item = state.collection.getItem(key);
102
+ if (item.type === "item") return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
103
+ key: item.key,
104
+ value: item.key
105
+ }, item.textValue);
106
+ }))));
107
+ else if (name) return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
108
+ type: "hidden",
109
+ autoComplete: selectProps.autoComplete,
110
+ name: name,
111
+ disabled: isDisabled,
112
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ""
113
+ });
114
+ return null;
115
+ }
116
+
117
+
118
+ export {$bdd25dc72710631f$export$f809e80f58e251d1 as useHiddenSelect, $bdd25dc72710631f$export$cbd84cdb2e668835 as HiddenSelect};
119
+ //# sourceMappingURL=HiddenSelect.mjs.map
@@ -0,0 +1,119 @@
1
+ import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSelect.module.js";
2
+ import $8BE50$react, {useRef as $8BE50$useRef} from "react";
3
+ import {useFormReset as $8BE50$useFormReset} from "@react-aria/utils";
4
+ import {useFormValidation as $8BE50$useFormValidation} from "@react-aria/form";
5
+ import {useInteractionModality as $8BE50$useInteractionModality} from "@react-aria/interactions";
6
+ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
7
+
8
+ /*
9
+ * Copyright 2020 Adobe. All rights reserved.
10
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License. You may obtain a copy
12
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software distributed under
15
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
16
+ * OF ANY KIND, either express or implied. See the License for the specific language
17
+ * governing permissions and limitations under the License.
18
+ */
19
+
20
+
21
+
22
+
23
+
24
+ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
25
+ let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
26
+ let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
27
+ let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
28
+ let modality = (0, $8BE50$useInteractionModality)();
29
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
30
+ (0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
31
+ (0, $8BE50$useFormValidation)({
32
+ validationBehavior: validationBehavior,
33
+ focus: ()=>triggerRef.current.focus()
34
+ }, state, props.selectRef);
35
+ var _state_selectedKey;
36
+ // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
37
+ // In Firefox, there must be a <label> to identify the <select> whereas other browsers
38
+ // seem to identify it just by surrounding text.
39
+ // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
40
+ // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
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
+ return {
55
+ containerProps: {
56
+ ...visuallyHiddenProps,
57
+ "aria-hidden": true,
58
+ ["data-hidden-select-ignore"]: true,
59
+ ["data-a11y-ignore"]: "aria-hidden-focus"
60
+ },
61
+ inputProps: {
62
+ type: "text",
63
+ tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,
64
+ style: {
65
+ fontSize: 16
66
+ },
67
+ onFocus: ()=>triggerRef.current.focus(),
68
+ disabled: isDisabled
69
+ },
70
+ selectProps: {
71
+ tabIndex: -1,
72
+ autoComplete: autoComplete,
73
+ disabled: isDisabled,
74
+ required: validationBehavior === "native" && isRequired,
75
+ name: name,
76
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : "",
77
+ onChange: (e)=>state.setSelectedKey(e.target.value)
78
+ }
79
+ };
80
+ }
81
+ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
82
+ let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
83
+ let selectRef = (0, $8BE50$useRef)(null);
84
+ let { containerProps: containerProps, inputProps: inputProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
85
+ ...props,
86
+ selectRef: selectRef
87
+ }, state, triggerRef);
88
+ var _state_selectedKey;
89
+ // If used in a <form>, use a hidden input so the value can be submitted to a server.
90
+ // If the collection isn't too big, use a hidden <select> element for this so that browser
91
+ // autofill will work. Otherwise, use an <input type="hidden">.
92
+ if (state.collection.size <= 300) return /*#__PURE__*/ (0, $8BE50$react).createElement("div", {
93
+ ...containerProps,
94
+ "data-testid": "hidden-select-container"
95
+ }, /*#__PURE__*/ (0, $8BE50$react).createElement("input", inputProps), /*#__PURE__*/ (0, $8BE50$react).createElement("label", null, label, /*#__PURE__*/ (0, $8BE50$react).createElement("select", {
96
+ ...selectProps,
97
+ ref: selectRef
98
+ }, /*#__PURE__*/ (0, $8BE50$react).createElement("option", null), [
99
+ ...state.collection.getKeys()
100
+ ].map((key)=>{
101
+ let item = state.collection.getItem(key);
102
+ if (item.type === "item") return /*#__PURE__*/ (0, $8BE50$react).createElement("option", {
103
+ key: item.key,
104
+ value: item.key
105
+ }, item.textValue);
106
+ }))));
107
+ else if (name) return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
108
+ type: "hidden",
109
+ autoComplete: selectProps.autoComplete,
110
+ name: name,
111
+ disabled: isDisabled,
112
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ""
113
+ });
114
+ return null;
115
+ }
116
+
117
+
118
+ export {$bdd25dc72710631f$export$f809e80f58e251d1 as useHiddenSelect, $bdd25dc72710631f$export$cbd84cdb2e668835 as HiddenSelect};
119
+ //# sourceMappingURL=HiddenSelect.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6CM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAAuC;IAC/H,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,WAAW,CAAA,GAAA,6BAAqB;IACpC,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,IAAM,WAAW,OAAO,CAAC,KAAK;IACvC,GAAG,OAAO,MAAM,SAAS;QAwCd;IAtCX,wFAAwF;IACxF,sFAAsF;IACtF,gDAAgD;IAChD,8FAA8F;IAC9F,kGAAkG;IAClG,mCAAmC;IACnC,EAAE;IACF,iGAAiG;IACjG,iGAAiG;IACjG,oGAAoG;IACpG,mGAAmG;IACnG,+FAA+F;IAC/F,+FAA+F;IAC/F,kEAAkE;IAClE,EAAE;IACF,kGAAkG;IAClG,+FAA+F;IAC/F,8FAA8F;IAC9F,OAAO;QACL,gBAAgB;YACd,GAAG,mBAAmB;YACtB,eAAe;YACf,CAAC,4BAA4B,EAAE;YAC/B,CAAC,mBAAmB,E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N,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} from '@react-types/shared';\nimport React, {ReactNode, RefObject, useRef} from 'react';\nimport {selectData} from './useSelect';\nimport {SelectState} from '@react-stately/select';\nimport {useFormReset} from '@react-aria/utils';\nimport {useFormValidation} from '@react-aria/form';\nimport {useInteractionModality} from '@react-aria/interactions';\nimport {useVisuallyHidden} from '@react-aria/visually-hidden';\n\nexport interface AriaHiddenSelectProps {\n /**\n * Describes the type of autocomplete functionality the input should provide if any. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).\n */\n autoComplete?: string,\n\n /** The text label for the select. */\n label?: ReactNode,\n\n /** HTML form input name. */\n name?: string,\n\n /** Sets the disabled state of the select and input. */\n isDisabled?: boolean\n}\n\nexport interface HiddenSelectProps<T> extends AriaHiddenSelectProps {\n /** State for the select. */\n state: SelectState<T>,\n\n /** A ref to the trigger element. */\n triggerRef: RefObject<FocusableElement>\n}\n\nexport interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {\n /** A ref to the hidden `<select>` element. */\n selectRef?: RefObject<HTMLSelectElement>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a hidden `<select>` element, which\n * can be used in combination with `useSelect` to support browser form autofill, mobile form\n * navigation, and native HTML form submission.\n */\nexport function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: SelectState<T>, triggerRef: RefObject<FocusableElement>) {\n let data = selectData.get(state) || {};\n let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\n let modality = useInteractionModality();\n let {visuallyHiddenProps} = useVisuallyHidden();\n\n useFormReset(props.selectRef, state.selectedKey, state.setSelectedKey);\n useFormValidation({\n validationBehavior,\n focus: () => triggerRef.current.focus()\n }, state, props.selectRef);\n\n // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.\n // In Firefox, there must be a <label> to identify the <select> whereas other browsers\n // seem to identify it just by surrounding text.\n // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a\n // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>\n // non tabbable with tabIndex={-1}.\n //\n // In mobile browsers, there are next/previous buttons above the software keyboard for navigating\n // between fields in a form. These only support native form inputs that are tabbable. In order to\n // support those, an additional hidden input is used to marshall focus to the button. It is tabbable\n // except when the button is focused, so that shift tab works properly to go to the actual previous\n // input in the form. Using the <select> for this also works, but Safari on iOS briefly flashes\n // the native menu on focus, so this isn't ideal. A font-size of 16px or greater is required to\n // prevent Safari from zooming in on the input when it is focused.\n //\n // If the current interaction modality is null, then the user hasn't interacted with the page yet.\n // In this case, we set the tabIndex to -1 on the input element so that automated accessibility\n // checkers don't throw false-positives about focusable elements inside an aria-hidden parent.\n return {\n containerProps: {\n ...visuallyHiddenProps,\n 'aria-hidden': true,\n ['data-hidden-select-ignore']: true,\n ['data-a11y-ignore']: 'aria-hidden-focus'\n },\n inputProps: {\n type: 'text',\n tabIndex: modality == null || state.isFocused || state.isOpen ? -1 : 0,\n style: {fontSize: 16},\n onFocus: () => triggerRef.current.focus(),\n disabled: isDisabled\n },\n selectProps: {\n tabIndex: -1,\n autoComplete,\n disabled: isDisabled,\n required: validationBehavior === 'native' && isRequired,\n name,\n value: state.selectedKey ?? '',\n onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value)\n }\n };\n}\n\n/**\n * Renders a hidden native `<select>` element, which can be used to support browser\n * form autofill, mobile form navigation, and native form submission.\n */\nexport function HiddenSelect<T>(props: HiddenSelectProps<T>) {\n let {state, triggerRef, label, name, isDisabled} = props;\n let selectRef = useRef(null);\n let {containerProps, inputProps, selectProps} = useHiddenSelect({...props, selectRef}, state, triggerRef);\n\n // If used in a <form>, use a hidden input so the value can be submitted to a server.\n // If the collection isn't too big, use a hidden <select> element for this so that browser\n // autofill will work. Otherwise, use an <input type=\"hidden\">.\n if (state.collection.size <= 300) {\n return (\n <div {...containerProps} data-testid=\"hidden-select-container\">\n <input {...inputProps} />\n <label>\n {label}\n <select {...selectProps} ref={selectRef}>\n <option />\n {[...state.collection.getKeys()].map(key => {\n let item = state.collection.getItem(key);\n if (item.type === 'item') {\n return (\n <option\n key={item.key}\n value={item.key}>\n {item.textValue}\n </option>\n );\n }\n })}\n </select>\n </label>\n </div>\n );\n } else if (name) {\n return (\n <input\n type=\"hidden\"\n autoComplete={selectProps.autoComplete}\n name={name}\n disabled={isDisabled}\n value={state.selectedKey ?? ''} />\n );\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"HiddenSelect.module.js.map"}