@react-aria/select 3.15.6 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,10 +32,17 @@ $parcel$export(module.exports, "HiddenSelect", () => $6eae0e0872a4cdd4$export$cb
32
32
 
33
33
  function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
34
34
  let data = (0, $23a1e93dc7fa8653$exports.selectData).get(state) || {};
35
- let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
35
+ let { autoComplete: autoComplete, name: name = data.name, form: form = data.form, isDisabled: isDisabled = data.isDisabled } = props;
36
36
  let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
37
- let { visuallyHiddenProps: visuallyHiddenProps } = (0, $ccxQv$reactariavisuallyhidden.useVisuallyHidden)();
38
- (0, $ccxQv$reactariautils.useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
37
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $ccxQv$reactariavisuallyhidden.useVisuallyHidden)({
38
+ style: {
39
+ // Prevent page scrolling.
40
+ position: 'fixed',
41
+ top: 0,
42
+ left: 0
43
+ }
44
+ });
45
+ (0, $ccxQv$reactariautils.useFormReset)(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);
39
46
  (0, $ccxQv$reactariaform.useFormValidation)({
40
47
  validationBehavior: validationBehavior,
41
48
  focus: ()=>{
@@ -43,6 +50,10 @@ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
43
50
  return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
44
51
  }
45
52
  }, state, props.selectRef);
53
+ // eslint-disable-next-line react-hooks/exhaustive-deps
54
+ let onChange = (0, $ccxQv$react.useCallback)((e)=>state.setSelectedKey(e.currentTarget.value), [
55
+ state.setSelectedKey
56
+ ]);
46
57
  var _state_selectedKey;
47
58
  // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
48
59
  // In Firefox, there must be a <label> to identify the <select> whereas other browsers
@@ -70,19 +81,21 @@ function $6eae0e0872a4cdd4$export$f809e80f58e251d1(props, state, triggerRef) {
70
81
  disabled: isDisabled,
71
82
  required: validationBehavior === 'native' && isRequired,
72
83
  name: name,
73
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : undefined,
74
- onChange: (e)=>state.setSelectedKey(e.target.value)
84
+ form: form,
85
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : '',
86
+ onChange: onChange,
87
+ onInput: onChange
75
88
  }
76
89
  };
77
90
  }
78
91
  function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
79
- let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
92
+ let { state: state, triggerRef: triggerRef, label: label, name: name, form: form, isDisabled: isDisabled } = props;
80
93
  let selectRef = (0, $ccxQv$react.useRef)(null);
94
+ let inputRef = (0, $ccxQv$react.useRef)(null);
81
95
  let { containerProps: containerProps, selectProps: selectProps } = $6eae0e0872a4cdd4$export$f809e80f58e251d1({
82
96
  ...props,
83
- selectRef: selectRef
97
+ selectRef: state.collection.size <= 300 ? selectRef : inputRef
84
98
  }, state, triggerRef);
85
- var _state_selectedKey;
86
99
  // If used in a <form>, use a hidden input so the value can be submitted to a server.
87
100
  // If the collection isn't too big, use a hidden <select> element for this so that browser
88
101
  // autofill will work. Otherwise, use an <input type="hidden">.
@@ -101,13 +114,35 @@ function $6eae0e0872a4cdd4$export$cbd84cdb2e668835(props) {
101
114
  value: item.key
102
115
  }, item.textValue);
103
116
  }))));
104
- else if (name) return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("input", {
105
- type: "hidden",
106
- autoComplete: selectProps.autoComplete,
107
- name: name,
108
- disabled: isDisabled,
109
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
110
- });
117
+ else if (name) {
118
+ let data = (0, $23a1e93dc7fa8653$exports.selectData).get(state) || {};
119
+ let { validationBehavior: validationBehavior } = data;
120
+ var _state_selectedKey;
121
+ let inputProps = {
122
+ type: 'hidden',
123
+ autoComplete: selectProps.autoComplete,
124
+ name: name,
125
+ form: form,
126
+ disabled: isDisabled,
127
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
128
+ };
129
+ if (validationBehavior === 'native') // Use a hidden <input type="text"> rather than <input type="hidden">
130
+ // so that an empty value blocks HTML form submission when the field is required.
131
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("input", {
132
+ ...inputProps,
133
+ ref: inputRef,
134
+ style: {
135
+ display: 'none'
136
+ },
137
+ type: "text",
138
+ required: selectProps.required,
139
+ onChange: ()=>{}
140
+ });
141
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($ccxQv$react))).createElement("input", {
142
+ ...inputProps,
143
+ ref: inputRef
144
+ });
145
+ }
111
146
  return null;
112
147
  }
113
148
 
@@ -1 +1 @@
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,sBA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KAAK,KAAK,GAAG;YACb,OAAO,KAAK,GAAG;WACd,KAAK,SAAS;IAIvB;SAKH,IAAI,MACT,qBACE,0DAAC;QACC,MAAK;QACL,cAAc,YAAY,YAAY;QACtC,MAAM;QACN,UAAU;QACV,OAAO,CAAA,qBAAA,MAAM,WAAW,cAAjB,gCAAA,qBAAqB;;IAIlC,OAAO;AACT","sources":["packages/@react-aria/select/src/HiddenSelect.tsx"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement, RefObject} from '@react-types/shared';\nimport React, {JSX, 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 ?? undefined,\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>): JSX.Element | null {\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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA8DM,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,QAAE,OAAO,KAAK,IAAI,cAAE,aAAa,KAAK,UAAU,EAAC,GAAG;IACvF,IAAI,sBAAC,kBAAkB,cAAE,UAAU,EAAC,GAAG;IACvC,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,gDAAgB,EAAE;QAC5C,OAAO;YACL,0BAA0B;YAC1B,UAAU;YACV,KAAK;YACL,MAAM;QACR;IACF;IAEA,CAAA,GAAA,kCAAW,EAAE,MAAM,SAAS,EAAE,MAAM,kBAAkB,EAAE,MAAM,cAAc;IAC5E,CAAA,GAAA,sCAAgB,EAAE;4BAChB;QACA,OAAO;gBAAM;oBAAA,sBAA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;qBAC5B,0DAAC,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,0DAAC;YACC,KAAK,KAAK,GAAG;YACb,OAAO,KAAK,GAAG;WACd,KAAK,SAAS;IAIvB;SAKH,IAAI,MAAM;QACf,IAAI,OAAO,CAAA,GAAA,oCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;QACrC,IAAI,sBAAC,kBAAkB,EAAC,GAAG;YAQlB;QANT,IAAI,aAAoD;YACtD,MAAM;YACN,cAAc,YAAY,YAAY;kBACtC;kBACA;YACA,UAAU;YACV,OAAO,CAAA,qBAAA,MAAM,WAAW,cAAjB,gCAAA,qBAAqB;QAC9B;QAEA,IAAI,uBAAuB,UACzB,qEAAqE;QACrE,iFAAiF;QACjF,qBACE,0DAAC;YACE,GAAG,UAAU;YACd,KAAK;YACL,OAAO;gBAAC,SAAS;YAAM;YACvB,MAAK;YACL,UAAU,YAAY,QAAQ;YAC9B,UAAU,KAAmC;;QAInD,qBACE,0DAAC;YAAO,GAAG,UAAU;YAAE,KAAK;;IAEhC;IAEA,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, {InputHTMLAttributes, JSX, ReactNode, useCallback, 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 /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).\n */\n form?: 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 | HTMLInputElement | 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, form = data.form, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n // Prevent page scrolling.\n position: 'fixed',\n top: 0,\n left: 0\n }\n });\n\n useFormReset(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);\n useFormValidation({\n validationBehavior,\n focus: () => triggerRef.current?.focus()\n }, state, props.selectRef);\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n let onChange = useCallback((e: React.ChangeEvent<HTMLSelectElement> | React.FormEvent<HTMLSelectElement>) => state.setSelectedKey(e.currentTarget.value), [state.setSelectedKey]);\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 form,\n value: state.selectedKey ?? '',\n onChange,\n onInput: onChange\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>): JSX.Element | null {\n let {state, triggerRef, label, name, form, isDisabled} = props;\n let selectRef = useRef(null);\n let inputRef = useRef(null);\n let {containerProps, selectProps} = useHiddenSelect({...props, selectRef: state.collection.size <= 300 ? selectRef : inputRef}, 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 let data = selectData.get(state) || {};\n let {validationBehavior} = data;\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = {\n type: 'hidden',\n autoComplete: selectProps.autoComplete,\n name,\n form,\n disabled: isDisabled,\n value: state.selectedKey ?? ''\n };\n\n if (validationBehavior === 'native') {\n // Use a hidden <input type=\"text\"> rather than <input type=\"hidden\">\n // so that an empty value blocks HTML form submission when the field is required.\n return (\n <input\n {...inputProps}\n ref={inputRef}\n style={{display: 'none'}}\n type=\"text\"\n required={selectProps.required}\n onChange={() => {/** Ignore react warning. */}} />\n );\n }\n\n return (\n <input {...inputProps} ref={inputRef} />\n );\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"HiddenSelect.main.js.map"}
@@ -1,5 +1,5 @@
1
1
  import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSelect.mjs";
2
- import $8BE50$react, {useRef as $8BE50$useRef} from "react";
2
+ import $8BE50$react, {useCallback as $8BE50$useCallback, 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
5
  import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
@@ -21,10 +21,17 @@ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visuall
21
21
 
22
22
  function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
23
23
  let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
24
- let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
24
+ let { autoComplete: autoComplete, name: name = data.name, form: form = data.form, isDisabled: isDisabled = data.isDisabled } = props;
25
25
  let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
26
- let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
27
- (0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
26
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)({
27
+ style: {
28
+ // Prevent page scrolling.
29
+ position: 'fixed',
30
+ top: 0,
31
+ left: 0
32
+ }
33
+ });
34
+ (0, $8BE50$useFormReset)(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);
28
35
  (0, $8BE50$useFormValidation)({
29
36
  validationBehavior: validationBehavior,
30
37
  focus: ()=>{
@@ -32,6 +39,10 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
32
39
  return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
33
40
  }
34
41
  }, state, props.selectRef);
42
+ // eslint-disable-next-line react-hooks/exhaustive-deps
43
+ let onChange = (0, $8BE50$useCallback)((e)=>state.setSelectedKey(e.currentTarget.value), [
44
+ state.setSelectedKey
45
+ ]);
35
46
  var _state_selectedKey;
36
47
  // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
37
48
  // In Firefox, there must be a <label> to identify the <select> whereas other browsers
@@ -59,19 +70,21 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
59
70
  disabled: isDisabled,
60
71
  required: validationBehavior === 'native' && isRequired,
61
72
  name: name,
62
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : undefined,
63
- onChange: (e)=>state.setSelectedKey(e.target.value)
73
+ form: form,
74
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : '',
75
+ onChange: onChange,
76
+ onInput: onChange
64
77
  }
65
78
  };
66
79
  }
67
80
  function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
68
- let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
81
+ let { state: state, triggerRef: triggerRef, label: label, name: name, form: form, isDisabled: isDisabled } = props;
69
82
  let selectRef = (0, $8BE50$useRef)(null);
83
+ let inputRef = (0, $8BE50$useRef)(null);
70
84
  let { containerProps: containerProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
71
85
  ...props,
72
- selectRef: selectRef
86
+ selectRef: state.collection.size <= 300 ? selectRef : inputRef
73
87
  }, state, triggerRef);
74
- var _state_selectedKey;
75
88
  // If used in a <form>, use a hidden input so the value can be submitted to a server.
76
89
  // If the collection isn't too big, use a hidden <select> element for this so that browser
77
90
  // autofill will work. Otherwise, use an <input type="hidden">.
@@ -90,13 +103,35 @@ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
90
103
  value: item.key
91
104
  }, item.textValue);
92
105
  }))));
93
- else if (name) return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
94
- type: "hidden",
95
- autoComplete: selectProps.autoComplete,
96
- name: name,
97
- disabled: isDisabled,
98
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
99
- });
106
+ else if (name) {
107
+ let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
108
+ let { validationBehavior: validationBehavior } = data;
109
+ var _state_selectedKey;
110
+ let inputProps = {
111
+ type: 'hidden',
112
+ autoComplete: selectProps.autoComplete,
113
+ name: name,
114
+ form: form,
115
+ disabled: isDisabled,
116
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
117
+ };
118
+ if (validationBehavior === 'native') // Use a hidden <input type="text"> rather than <input type="hidden">
119
+ // so that an empty value blocks HTML form submission when the field is required.
120
+ return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
121
+ ...inputProps,
122
+ ref: inputRef,
123
+ style: {
124
+ display: 'none'
125
+ },
126
+ type: "text",
127
+ required: selectProps.required,
128
+ onChange: ()=>{}
129
+ });
130
+ return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
131
+ ...inputProps,
132
+ ref: inputRef
133
+ });
134
+ }
100
135
  return null;
101
136
  }
102
137
 
@@ -1,5 +1,5 @@
1
1
  import {selectData as $58aed456727eb0f3$export$703601b7e90536f8} from "./useSelect.module.js";
2
- import $8BE50$react, {useRef as $8BE50$useRef} from "react";
2
+ import $8BE50$react, {useCallback as $8BE50$useCallback, 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
5
  import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visually-hidden";
@@ -21,10 +21,17 @@ import {useVisuallyHidden as $8BE50$useVisuallyHidden} from "@react-aria/visuall
21
21
 
22
22
  function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
23
23
  let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
24
- let { autoComplete: autoComplete, name: name = data.name, isDisabled: isDisabled = data.isDisabled } = props;
24
+ let { autoComplete: autoComplete, name: name = data.name, form: form = data.form, isDisabled: isDisabled = data.isDisabled } = props;
25
25
  let { validationBehavior: validationBehavior, isRequired: isRequired } = data;
26
- let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)();
27
- (0, $8BE50$useFormReset)(props.selectRef, state.selectedKey, state.setSelectedKey);
26
+ let { visuallyHiddenProps: visuallyHiddenProps } = (0, $8BE50$useVisuallyHidden)({
27
+ style: {
28
+ // Prevent page scrolling.
29
+ position: 'fixed',
30
+ top: 0,
31
+ left: 0
32
+ }
33
+ });
34
+ (0, $8BE50$useFormReset)(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);
28
35
  (0, $8BE50$useFormValidation)({
29
36
  validationBehavior: validationBehavior,
30
37
  focus: ()=>{
@@ -32,6 +39,10 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
32
39
  return (_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
33
40
  }
34
41
  }, state, props.selectRef);
42
+ // eslint-disable-next-line react-hooks/exhaustive-deps
43
+ let onChange = (0, $8BE50$useCallback)((e)=>state.setSelectedKey(e.currentTarget.value), [
44
+ state.setSelectedKey
45
+ ]);
35
46
  var _state_selectedKey;
36
47
  // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
37
48
  // In Firefox, there must be a <label> to identify the <select> whereas other browsers
@@ -59,19 +70,21 @@ function $bdd25dc72710631f$export$f809e80f58e251d1(props, state, triggerRef) {
59
70
  disabled: isDisabled,
60
71
  required: validationBehavior === 'native' && isRequired,
61
72
  name: name,
62
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : undefined,
63
- onChange: (e)=>state.setSelectedKey(e.target.value)
73
+ form: form,
74
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : '',
75
+ onChange: onChange,
76
+ onInput: onChange
64
77
  }
65
78
  };
66
79
  }
67
80
  function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
68
- let { state: state, triggerRef: triggerRef, label: label, name: name, isDisabled: isDisabled } = props;
81
+ let { state: state, triggerRef: triggerRef, label: label, name: name, form: form, isDisabled: isDisabled } = props;
69
82
  let selectRef = (0, $8BE50$useRef)(null);
83
+ let inputRef = (0, $8BE50$useRef)(null);
70
84
  let { containerProps: containerProps, selectProps: selectProps } = $bdd25dc72710631f$export$f809e80f58e251d1({
71
85
  ...props,
72
- selectRef: selectRef
86
+ selectRef: state.collection.size <= 300 ? selectRef : inputRef
73
87
  }, state, triggerRef);
74
- var _state_selectedKey;
75
88
  // If used in a <form>, use a hidden input so the value can be submitted to a server.
76
89
  // If the collection isn't too big, use a hidden <select> element for this so that browser
77
90
  // autofill will work. Otherwise, use an <input type="hidden">.
@@ -90,13 +103,35 @@ function $bdd25dc72710631f$export$cbd84cdb2e668835(props) {
90
103
  value: item.key
91
104
  }, item.textValue);
92
105
  }))));
93
- else if (name) return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
94
- type: "hidden",
95
- autoComplete: selectProps.autoComplete,
96
- name: name,
97
- disabled: isDisabled,
98
- value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
99
- });
106
+ else if (name) {
107
+ let data = (0, $58aed456727eb0f3$export$703601b7e90536f8).get(state) || {};
108
+ let { validationBehavior: validationBehavior } = data;
109
+ var _state_selectedKey;
110
+ let inputProps = {
111
+ type: 'hidden',
112
+ autoComplete: selectProps.autoComplete,
113
+ name: name,
114
+ form: form,
115
+ disabled: isDisabled,
116
+ value: (_state_selectedKey = state.selectedKey) !== null && _state_selectedKey !== void 0 ? _state_selectedKey : ''
117
+ };
118
+ if (validationBehavior === 'native') // Use a hidden <input type="text"> rather than <input type="hidden">
119
+ // so that an empty value blocks HTML form submission when the field is required.
120
+ return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
121
+ ...inputProps,
122
+ ref: inputRef,
123
+ style: {
124
+ display: 'none'
125
+ },
126
+ type: "text",
127
+ required: selectProps.required,
128
+ onChange: ()=>{}
129
+ });
130
+ return /*#__PURE__*/ (0, $8BE50$react).createElement("input", {
131
+ ...inputProps,
132
+ ref: inputRef
133
+ });
134
+ }
100
135
  return null;
101
136
  }
102
137
 
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuDM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAA8C;IACtI,IAAI,OAAO,CAAA,GAAA,yCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,gBAAC,YAAY,QAAE,OAAO,KAAK,IAAI,cAAE,aAAa,KAAK,UAAU,EAAC,GAAG;IACrE,IAAI,sBAAC,kBAAkB,cAAE,UAAU,EAAC,GAAG;IAC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W;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, {JSX, 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 ?? undefined,\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>): JSX.Element | null {\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"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA8DM,SAAS,0CAAmB,KAA8B,EAAE,KAAqB,EAAE,UAA8C;IACtI,IAAI,OAAO,CAAA,GAAA,yCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;IACrC,IAAI,gBAAC,YAAY,QAAE,OAAO,KAAK,IAAI,QAAE,OAAO,KAAK,IAAI,cAAE,aAAa,KAAK,UAAU,EAAC,GAAG;IACvF,IAAI,sBAAC,kBAAkB,cAAE,UAAU,EAAC,GAAG;IACvC,IAAI,uBAAC,mBAAmB,EAAC,GAAG,CAAA,GAAA,wBAAgB,EAAE;QAC5C,OAAO;YACL,0BAA0B;YAC1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qF;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,MAAM;QACf,IAAI,OAAO,CAAA,GAAA,yCAAS,EAAE,GAAG,CAAC,UAAU,CAAC;QACrC,IAAI,sBAAC,kBAAkB,EAAC,GAAG;YAQlB;QANT,IAAI,aAAoD;YACtD,MAAM;YACN,cAAc,YAAY,YAAY;kBACtC;kBACA;YACA,UAAU;YACV,OAAO,CAAA,qBAAA,MAAM,WAAW,cAAjB,gCAAA,qBAAqB;QAC9B;QAEA,IAAI,uBAAuB,UACzB,qEAAqE;QACrE,iFAAiF;QACjF,qBACE,gCAAC;YACE,GAAG,UAAU;YACd,KAAK;YACL,OAAO;gBAAC,SAAS;YAAM;YACvB,MAAK;YACL,UAAU,YAAY,QAAQ;YAC9B,UAAU,KAAmC;;QAInD,qBACE,gCAAC;YAAO,GAAG,UAAU;YAAE,KAAK;;IAEhC;IAEA,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, {InputHTMLAttributes, JSX, ReactNode, useCallback, 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 /**\n * The `<form>` element to associate the input with.\n * The value of this attribute must be the id of a `<form>` in the same document.\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).\n */\n form?: 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 | HTMLInputElement | 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, form = data.form, isDisabled = data.isDisabled} = props;\n let {validationBehavior, isRequired} = data;\n let {visuallyHiddenProps} = useVisuallyHidden({\n style: {\n // Prevent page scrolling.\n position: 'fixed',\n top: 0,\n left: 0\n }\n });\n\n useFormReset(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);\n useFormValidation({\n validationBehavior,\n focus: () => triggerRef.current?.focus()\n }, state, props.selectRef);\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n let onChange = useCallback((e: React.ChangeEvent<HTMLSelectElement> | React.FormEvent<HTMLSelectElement>) => state.setSelectedKey(e.currentTarget.value), [state.setSelectedKey]);\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 form,\n value: state.selectedKey ?? '',\n onChange,\n onInput: onChange\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>): JSX.Element | null {\n let {state, triggerRef, label, name, form, isDisabled} = props;\n let selectRef = useRef(null);\n let inputRef = useRef(null);\n let {containerProps, selectProps} = useHiddenSelect({...props, selectRef: state.collection.size <= 300 ? selectRef : inputRef}, 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 let data = selectData.get(state) || {};\n let {validationBehavior} = data;\n\n let inputProps: InputHTMLAttributes<HTMLInputElement> = {\n type: 'hidden',\n autoComplete: selectProps.autoComplete,\n name,\n form,\n disabled: isDisabled,\n value: state.selectedKey ?? ''\n };\n\n if (validationBehavior === 'native') {\n // Use a hidden <input type=\"text\"> rather than <input type=\"hidden\">\n // so that an empty value blocks HTML form submission when the field is required.\n return (\n <input\n {...inputProps}\n ref={inputRef}\n style={{display: 'none'}}\n type=\"text\"\n required={selectProps.required}\n onChange={() => {/** Ignore react warning. */}} />\n );\n }\n\n return (\n <input {...inputProps} ref={inputRef} />\n );\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"HiddenSelect.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,37 +1,9 @@
1
+ import { FocusableElement, RefObject, DOMAttributes, KeyboardDelegate, ValidationResult } from "@react-types/shared";
2
+ import React, { JSX, ReactNode } from "react";
3
+ import { SelectState } from "@react-stately/select";
1
4
  import { AriaButtonProps } from "@react-types/button";
2
5
  import { AriaListBoxOptions } from "@react-aria/listbox";
3
6
  import { AriaSelectProps } from "@react-types/select";
4
- import { DOMAttributes, KeyboardDelegate, RefObject, ValidationResult, FocusableElement } from "@react-types/shared";
5
- import { SelectState } from "@react-stately/select";
6
- import React, { JSX, ReactNode } from "react";
7
- export interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {
8
- /**
9
- * An optional keyboard delegate implementation for type to select,
10
- * to override the default.
11
- */
12
- keyboardDelegate?: KeyboardDelegate;
13
- }
14
- export interface SelectAria<T> extends ValidationResult {
15
- /** Props for the label element. */
16
- labelProps: DOMAttributes;
17
- /** Props for the popup trigger element. */
18
- triggerProps: AriaButtonProps;
19
- /** Props for the element representing the selected value. */
20
- valueProps: DOMAttributes;
21
- /** Props for the popup. */
22
- menuProps: AriaListBoxOptions<T>;
23
- /** Props for the select's description element, if any. */
24
- descriptionProps: DOMAttributes;
25
- /** Props for the select's error message element, if any. */
26
- errorMessageProps: DOMAttributes;
27
- }
28
- /**
29
- * Provides the behavior and accessibility implementation for a select component.
30
- * A select displays a collapsible list of options and allows a user to select one of them.
31
- * @param props - Props for the select.
32
- * @param state - State for the select, as returned by `useListState`.
33
- */
34
- export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<HTMLElement | null>): SelectAria<T>;
35
7
  export interface AriaHiddenSelectProps {
36
8
  /**
37
9
  * 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).
@@ -41,6 +13,12 @@ export interface AriaHiddenSelectProps {
41
13
  label?: ReactNode;
42
14
  /** HTML form input name. */
43
15
  name?: string;
16
+ /**
17
+ * The `<form>` element to associate the input with.
18
+ * The value of this attribute must be the id of a `<form>` in the same document.
19
+ * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).
20
+ */
21
+ form?: string;
44
22
  /** Sets the disabled state of the select and input. */
45
23
  isDisabled?: boolean;
46
24
  }
@@ -52,7 +30,7 @@ export interface HiddenSelectProps<T> extends AriaHiddenSelectProps {
52
30
  }
53
31
  interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {
54
32
  /** A ref to the hidden `<select>` element. */
55
- selectRef?: RefObject<HTMLSelectElement | null>;
33
+ selectRef?: RefObject<HTMLSelectElement | HTMLInputElement | null>;
56
34
  }
57
35
  interface HiddenSelectAria {
58
36
  /** Props for the container element. */
@@ -73,6 +51,36 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
73
51
  * form autofill, mobile form navigation, and native form submission.
74
52
  */
75
53
  export function HiddenSelect<T>(props: HiddenSelectProps<T>): JSX.Element | null;
54
+ export interface AriaSelectOptions<T> extends Omit<AriaSelectProps<T>, 'children'> {
55
+ /**
56
+ * An optional keyboard delegate implementation for type to select,
57
+ * to override the default.
58
+ */
59
+ keyboardDelegate?: KeyboardDelegate;
60
+ }
61
+ export interface SelectAria<T> extends ValidationResult {
62
+ /** Props for the label element. */
63
+ labelProps: DOMAttributes;
64
+ /** Props for the popup trigger element. */
65
+ triggerProps: AriaButtonProps;
66
+ /** Props for the element representing the selected value. */
67
+ valueProps: DOMAttributes;
68
+ /** Props for the popup. */
69
+ menuProps: AriaListBoxOptions<T>;
70
+ /** Props for the select's description element, if any. */
71
+ descriptionProps: DOMAttributes;
72
+ /** Props for the select's error message element, if any. */
73
+ errorMessageProps: DOMAttributes;
74
+ /** Props for the hidden select element. */
75
+ hiddenSelectProps: HiddenSelectProps<T>;
76
+ }
77
+ /**
78
+ * Provides the behavior and accessibility implementation for a select component.
79
+ * A select displays a collapsible list of options and allows a user to select one of them.
80
+ * @param props - Props for the select.
81
+ * @param state - State for the select, as returned by `useListState`.
82
+ */
83
+ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>, ref: RefObject<HTMLElement | null>): SelectAria<T>;
76
84
  export type { AriaSelectProps } from '@react-types/select';
77
85
 
78
86
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAyBA,mCAAmC,CAAC,CAAE,SAAQ,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,UAAU,CAAC;IAChF;;;OAGG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;CACpC;AAED,4BAA4B,CAAC,CAAE,SAAQ,gBAAgB;IACrD,mCAAmC;IACnC,UAAU,EA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AAC,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,GAAG,IAAI,OAAO,GAAG,IAAI,CA2C/E;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"}
1
+ {"mappings":";;;;;;AAoBA;IACE;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,qCAAqC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,uDAAuD;IACvD,UAAU,CAAC,EAAE,OAAO,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AC1D,gBAAgB,EAAE,aAAa,CAAC;IAEhC,4DAA4D;IAC5D,iBAAiB,EAAE,aAAa,CAAC;IAEjC,2CAA2C;IAC3C,iBAAiB,EAAE,kBAAkB,CAAC,CAAC,CAAA;CACxC;AAYD;;;;;GAKG;AACH,0BAA0B,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC,CAkLlI;AC5OD,YAAY,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/select/src/packages/@react-aria/select/src/HiddenSelect.tsx","packages/@react-aria/select/src/packages/@react-aria/select/src/useSelect.ts","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"}
@@ -32,7 +32,7 @@ $parcel$export(module.exports, "useSelect", () => $23a1e93dc7fa8653$export$e64b2
32
32
 
33
33
  const $23a1e93dc7fa8653$export$703601b7e90536f8 = new WeakMap();
34
34
  function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
35
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = 'aria' } = props;
35
+ let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
36
36
  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
37
37
  // When virtualized, the layout object will be passed in as a prop and override this.
38
38
  let collator = (0, $63cuq$reactariai18n.useCollator)({
@@ -97,6 +97,7 @@ function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
97
97
  isDisabled: isDisabled,
98
98
  isRequired: isRequired,
99
99
  name: name,
100
+ form: form,
100
101
  validationBehavior: validationBehavior
101
102
  });
102
103
  return {
@@ -159,7 +160,15 @@ function $23a1e93dc7fa8653$export$e64b2f635402ca43(props, state, ref) {
159
160
  errorMessageProps: errorMessageProps,
160
161
  isInvalid: isInvalid,
161
162
  validationErrors: validationErrors,
162
- validationDetails: validationDetails
163
+ validationDetails: validationDetails,
164
+ hiddenSelectProps: {
165
+ isDisabled: isDisabled,
166
+ name: name,
167
+ label: props.label,
168
+ state: state,
169
+ triggerRef: ref,
170
+ form: form
171
+ }
163
172
  };
164
173
  }
165
174
 
@@ -1 +1 @@
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,E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;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, ref]);\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;;;;;;;AAuDM,MAAM,4CAAoD,IAAI;AAQ9D,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAkC;IACjH,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,QACJ,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;QAAU;KAAI;IAEvM,IAAI,oBAAC,gBAAgB,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,mCAAa,EAC/C;oBACE;QACA,MAAM;IACR,GACA,OACA;IAGF,IAAI,Y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AAM,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;QACA,mBAAmB;wBACjB;kBACA;YACA,OAAO,MAAM,KAAK;mBAClB;YACA,YAAY;kBACZ;QACF;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 {HiddenSelectProps} from './HiddenSelect';\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 /** Props for the hidden select element. */\n hiddenSelectProps: HiddenSelectProps<T>\n}\n\ninterface SelectData {\n isDisabled?: boolean,\n isRequired?: boolean,\n name?: string,\n form?: string,\n validationBehavior?: 'aria' | 'native'\n}\n\nexport const selectData: WeakMap<SelectState<any>, 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 form,\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, ref]);\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 form,\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 hiddenSelectProps: {\n isDisabled,\n name,\n label: props.label,\n state,\n triggerRef: ref,\n form\n }\n };\n}\n"],"names":[],"version":3,"file":"useSelect.main.js.map"}
@@ -25,7 +25,7 @@ import {useMenuTrigger as $aUnai$useMenuTrigger} from "@react-aria/menu";
25
25
 
26
26
  const $58aed456727eb0f3$export$703601b7e90536f8 = new WeakMap();
27
27
  function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
28
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = 'aria' } = props;
28
+ let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
29
29
  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
30
30
  // When virtualized, the layout object will be passed in as a prop and override this.
31
31
  let collator = (0, $aUnai$useCollator)({
@@ -90,6 +90,7 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
90
90
  isDisabled: isDisabled,
91
91
  isRequired: isRequired,
92
92
  name: name,
93
+ form: form,
93
94
  validationBehavior: validationBehavior
94
95
  });
95
96
  return {
@@ -152,7 +153,15 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
152
153
  errorMessageProps: errorMessageProps,
153
154
  isInvalid: isInvalid,
154
155
  validationErrors: validationErrors,
155
- validationDetails: validationDetails
156
+ validationDetails: validationDetails,
157
+ hiddenSelectProps: {
158
+ isDisabled: isDisabled,
159
+ name: name,
160
+ label: props.label,
161
+ state: state,
162
+ triggerRef: ref,
163
+ form: form
164
+ }
156
165
  };
157
166
  }
158
167
 
@@ -25,7 +25,7 @@ import {useMenuTrigger as $aUnai$useMenuTrigger} from "@react-aria/menu";
25
25
 
26
26
  const $58aed456727eb0f3$export$703601b7e90536f8 = new WeakMap();
27
27
  function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
28
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, validationBehavior: validationBehavior = 'aria' } = props;
28
+ let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
29
29
  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
30
30
  // When virtualized, the layout object will be passed in as a prop and override this.
31
31
  let collator = (0, $aUnai$useCollator)({
@@ -90,6 +90,7 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
90
90
  isDisabled: isDisabled,
91
91
  isRequired: isRequired,
92
92
  name: name,
93
+ form: form,
93
94
  validationBehavior: validationBehavior
94
95
  });
95
96
  return {
@@ -152,7 +153,15 @@ function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
152
153
  errorMessageProps: errorMessageProps,
153
154
  isInvalid: isInvalid,
154
155
  validationErrors: validationErrors,
155
- validationDetails: validationDetails
156
+ validationDetails: validationDetails,
157
+ hiddenSelectProps: {
158
+ isDisabled: isDisabled,
159
+ name: name,
160
+ label: props.label,
161
+ state: state,
162
+ triggerRef: ref,
163
+ form: form
164
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C,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, 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, ref]);\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;;;;;;;AAuDM,MAAM,4CAAoD,IAAI;AAQ9D,SAAS,0CAAa,KAA2B,EAAE,KAAqB,EAAE,GAAkC;IACjH,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,QACJ,IAAI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AGtB,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;QACA,mBAAmB;wBACjB;kBACA;YACA,OAAO,MAAM,KAAK;mBAClB;YACA,YAAY;kBACZ;QACF;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 {HiddenSelectProps} from './HiddenSelect';\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 /** Props for the hidden select element. */\n hiddenSelectProps: HiddenSelectProps<T>\n}\n\ninterface SelectData {\n isDisabled?: boolean,\n isRequired?: boolean,\n name?: string,\n form?: string,\n validationBehavior?: 'aria' | 'native'\n}\n\nexport const selectData: WeakMap<SelectState<any>, 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 form,\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, ref]);\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 form,\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 hiddenSelectProps: {\n isDisabled,\n name,\n label: props.label,\n state,\n triggerRef: ref,\n form\n }\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.15.6",
3
+ "version": "3.16.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,19 +26,19 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/form": "^3.0.17",
30
- "@react-aria/i18n": "^3.12.10",
31
- "@react-aria/interactions": "^3.25.2",
32
- "@react-aria/label": "^3.7.19",
33
- "@react-aria/listbox": "^3.14.5",
34
- "@react-aria/menu": "^3.18.4",
35
- "@react-aria/selection": "^3.24.2",
36
- "@react-aria/utils": "^3.29.1",
37
- "@react-aria/visually-hidden": "^3.8.24",
38
- "@react-stately/select": "^3.6.14",
39
- "@react-types/button": "^3.12.2",
40
- "@react-types/select": "^3.9.13",
41
- "@react-types/shared": "^3.30.0",
29
+ "@react-aria/form": "^3.1.0",
30
+ "@react-aria/i18n": "^3.12.11",
31
+ "@react-aria/interactions": "^3.25.4",
32
+ "@react-aria/label": "^3.7.20",
33
+ "@react-aria/listbox": "^3.14.7",
34
+ "@react-aria/menu": "^3.19.0",
35
+ "@react-aria/selection": "^3.25.0",
36
+ "@react-aria/utils": "^3.30.0",
37
+ "@react-aria/visually-hidden": "^3.8.26",
38
+ "@react-stately/select": "^3.7.0",
39
+ "@react-types/button": "^3.13.0",
40
+ "@react-types/select": "^3.10.0",
41
+ "@react-types/shared": "^3.31.0",
42
42
  "@swc/helpers": "^0.5.0"
43
43
  },
44
44
  "peerDependencies": {
@@ -48,5 +48,5 @@
48
48
  "publishConfig": {
49
49
  "access": "public"
50
50
  },
51
- "gitHead": "265b4d7f107905ee1c6e87a8af1613ab440a6849"
51
+ "gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
52
52
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {FocusableElement, RefObject} from '@react-types/shared';
14
- import React, {JSX, ReactNode, useRef} from 'react';
14
+ import React, {InputHTMLAttributes, JSX, ReactNode, useCallback, useRef} from 'react';
15
15
  import {selectData} from './useSelect';
16
16
  import {SelectState} from '@react-stately/select';
17
17
  import {useFormReset} from '@react-aria/utils';
@@ -30,6 +30,13 @@ export interface AriaHiddenSelectProps {
30
30
  /** HTML form input name. */
31
31
  name?: string,
32
32
 
33
+ /**
34
+ * The `<form>` element to associate the input with.
35
+ * The value of this attribute must be the id of a `<form>` in the same document.
36
+ * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).
37
+ */
38
+ form?: string,
39
+
33
40
  /** Sets the disabled state of the select and input. */
34
41
  isDisabled?: boolean
35
42
  }
@@ -44,7 +51,7 @@ export interface HiddenSelectProps<T> extends AriaHiddenSelectProps {
44
51
 
45
52
  export interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {
46
53
  /** A ref to the hidden `<select>` element. */
47
- selectRef?: RefObject<HTMLSelectElement | null>
54
+ selectRef?: RefObject<HTMLSelectElement | HTMLInputElement | null>
48
55
  }
49
56
 
50
57
  export interface HiddenSelectAria {
@@ -65,16 +72,26 @@ export interface HiddenSelectAria {
65
72
  */
66
73
  export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: SelectState<T>, triggerRef: RefObject<FocusableElement | null>): HiddenSelectAria {
67
74
  let data = selectData.get(state) || {};
68
- let {autoComplete, name = data.name, isDisabled = data.isDisabled} = props;
75
+ let {autoComplete, name = data.name, form = data.form, isDisabled = data.isDisabled} = props;
69
76
  let {validationBehavior, isRequired} = data;
70
- let {visuallyHiddenProps} = useVisuallyHidden();
77
+ let {visuallyHiddenProps} = useVisuallyHidden({
78
+ style: {
79
+ // Prevent page scrolling.
80
+ position: 'fixed',
81
+ top: 0,
82
+ left: 0
83
+ }
84
+ });
71
85
 
72
- useFormReset(props.selectRef, state.selectedKey, state.setSelectedKey);
86
+ useFormReset(props.selectRef, state.defaultSelectedKey, state.setSelectedKey);
73
87
  useFormValidation({
74
88
  validationBehavior,
75
89
  focus: () => triggerRef.current?.focus()
76
90
  }, state, props.selectRef);
77
91
 
92
+ // eslint-disable-next-line react-hooks/exhaustive-deps
93
+ let onChange = useCallback((e: React.ChangeEvent<HTMLSelectElement> | React.FormEvent<HTMLSelectElement>) => state.setSelectedKey(e.currentTarget.value), [state.setSelectedKey]);
94
+
78
95
  // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
79
96
  // In Firefox, there must be a <label> to identify the <select> whereas other browsers
80
97
  // seem to identify it just by surrounding text.
@@ -99,8 +116,10 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
99
116
  disabled: isDisabled,
100
117
  required: validationBehavior === 'native' && isRequired,
101
118
  name,
102
- value: state.selectedKey ?? undefined,
103
- onChange: (e: React.ChangeEvent<HTMLSelectElement>) => state.setSelectedKey(e.target.value)
119
+ form,
120
+ value: state.selectedKey ?? '',
121
+ onChange,
122
+ onInput: onChange
104
123
  }
105
124
  };
106
125
  }
@@ -110,9 +129,10 @@ export function useHiddenSelect<T>(props: AriaHiddenSelectOptions, state: Select
110
129
  * form autofill, mobile form navigation, and native form submission.
111
130
  */
112
131
  export function HiddenSelect<T>(props: HiddenSelectProps<T>): JSX.Element | null {
113
- let {state, triggerRef, label, name, isDisabled} = props;
132
+ let {state, triggerRef, label, name, form, isDisabled} = props;
114
133
  let selectRef = useRef(null);
115
- let {containerProps, selectProps} = useHiddenSelect({...props, selectRef}, state, triggerRef);
134
+ let inputRef = useRef(null);
135
+ let {containerProps, selectProps} = useHiddenSelect({...props, selectRef: state.collection.size <= 300 ? selectRef : inputRef}, state, triggerRef);
116
136
 
117
137
  // If used in a <form>, use a hidden input so the value can be submitted to a server.
118
138
  // If the collection isn't too big, use a hidden <select> element for this so that browser
@@ -141,13 +161,34 @@ export function HiddenSelect<T>(props: HiddenSelectProps<T>): JSX.Element | null
141
161
  </div>
142
162
  );
143
163
  } else if (name) {
164
+ let data = selectData.get(state) || {};
165
+ let {validationBehavior} = data;
166
+
167
+ let inputProps: InputHTMLAttributes<HTMLInputElement> = {
168
+ type: 'hidden',
169
+ autoComplete: selectProps.autoComplete,
170
+ name,
171
+ form,
172
+ disabled: isDisabled,
173
+ value: state.selectedKey ?? ''
174
+ };
175
+
176
+ if (validationBehavior === 'native') {
177
+ // Use a hidden <input type="text"> rather than <input type="hidden">
178
+ // so that an empty value blocks HTML form submission when the field is required.
179
+ return (
180
+ <input
181
+ {...inputProps}
182
+ ref={inputRef}
183
+ style={{display: 'none'}}
184
+ type="text"
185
+ required={selectProps.required}
186
+ onChange={() => {/** Ignore react warning. */}} />
187
+ );
188
+ }
189
+
144
190
  return (
145
- <input
146
- type="hidden"
147
- autoComplete={selectProps.autoComplete}
148
- name={name}
149
- disabled={isDisabled}
150
- value={state.selectedKey ?? ''} />
191
+ <input {...inputProps} ref={inputRef} />
151
192
  );
152
193
  }
153
194
 
package/src/useSelect.ts CHANGED
@@ -16,6 +16,7 @@ import {AriaSelectProps} from '@react-types/select';
16
16
  import {chain, filterDOMProps, mergeProps, useId} from '@react-aria/utils';
17
17
  import {DOMAttributes, KeyboardDelegate, RefObject, ValidationResult} from '@react-types/shared';
18
18
  import {FocusEvent, useMemo} from 'react';
19
+ import {HiddenSelectProps} from './HiddenSelect';
19
20
  import {ListKeyboardDelegate, useTypeSelect} from '@react-aria/selection';
20
21
  import {SelectState} from '@react-stately/select';
21
22
  import {setInteractionModality} from '@react-aria/interactions';
@@ -48,17 +49,21 @@ export interface SelectAria<T> extends ValidationResult {
48
49
  descriptionProps: DOMAttributes,
49
50
 
50
51
  /** Props for the select's error message element, if any. */
51
- errorMessageProps: DOMAttributes
52
+ errorMessageProps: DOMAttributes,
53
+
54
+ /** Props for the hidden select element. */
55
+ hiddenSelectProps: HiddenSelectProps<T>
52
56
  }
53
57
 
54
58
  interface SelectData {
55
59
  isDisabled?: boolean,
56
60
  isRequired?: boolean,
57
61
  name?: string,
62
+ form?: string,
58
63
  validationBehavior?: 'aria' | 'native'
59
64
  }
60
65
 
61
- export const selectData = new WeakMap<SelectState<any>, SelectData>();
66
+ export const selectData: WeakMap<SelectState<any>, SelectData> = new WeakMap<SelectState<any>, SelectData>();
62
67
 
63
68
  /**
64
69
  * Provides the behavior and accessibility implementation for a select component.
@@ -72,6 +77,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
72
77
  isDisabled,
73
78
  isRequired,
74
79
  name,
80
+ form,
75
81
  validationBehavior = 'aria'
76
82
  } = props;
77
83
 
@@ -142,6 +148,7 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
142
148
  isDisabled,
143
149
  isRequired,
144
150
  name,
151
+ form,
145
152
  validationBehavior
146
153
  });
147
154
 
@@ -232,6 +239,14 @@ export function useSelect<T>(props: AriaSelectOptions<T>, state: SelectState<T>,
232
239
  errorMessageProps,
233
240
  isInvalid,
234
241
  validationErrors,
235
- validationDetails
242
+ validationDetails,
243
+ hiddenSelectProps: {
244
+ isDisabled,
245
+ name,
246
+ label: props.label,
247
+ state,
248
+ triggerRef: ref,
249
+ form
250
+ }
236
251
  };
237
252
  }