@react-aria/select 3.17.3 → 3.18.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.
@@ -1,172 +0,0 @@
1
- import {filterDOMProps as $aUnai$filterDOMProps, mergeProps as $aUnai$mergeProps, useId as $aUnai$useId, chain as $aUnai$chain, nodeContains as $aUnai$nodeContains} from "@react-aria/utils";
2
- import {useMemo as $aUnai$useMemo} from "react";
3
- import {ListKeyboardDelegate as $aUnai$ListKeyboardDelegate, useTypeSelect as $aUnai$useTypeSelect} from "@react-aria/selection";
4
- import {setInteractionModality as $aUnai$setInteractionModality} from "@react-aria/interactions";
5
- import {useCollator as $aUnai$useCollator} from "@react-aria/i18n";
6
- import {useField as $aUnai$useField} from "@react-aria/label";
7
- import {useMenuTrigger as $aUnai$useMenuTrigger} from "@react-aria/menu";
8
-
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
-
21
-
22
-
23
-
24
-
25
-
26
- const $58aed456727eb0f3$export$703601b7e90536f8 = new WeakMap();
27
- function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
28
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
29
- // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
30
- // When virtualized, the layout object will be passed in as a prop and override this.
31
- let collator = (0, $aUnai$useCollator)({
32
- usage: 'search',
33
- sensitivity: 'base'
34
- });
35
- let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys, ref, collator), [
36
- keyboardDelegate,
37
- state.collection,
38
- state.disabledKeys,
39
- collator,
40
- ref
41
- ]);
42
- let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $aUnai$useMenuTrigger)({
43
- isDisabled: isDisabled,
44
- type: 'listbox'
45
- }, state, ref);
46
- let onKeyDown = (e)=>{
47
- if (state.selectionManager.selectionMode === 'multiple') return;
48
- switch(e.key){
49
- case 'ArrowLeft':
50
- {
51
- var _delegate_getKeyAbove, _delegate_getFirstKey;
52
- // prevent scrolling containers
53
- e.preventDefault();
54
- let key = state.selectedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, state.selectedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
55
- if (key) state.setSelectedKey(key);
56
- break;
57
- }
58
- case 'ArrowRight':
59
- {
60
- var _delegate_getKeyBelow, _delegate_getFirstKey1;
61
- // prevent scrolling containers
62
- e.preventDefault();
63
- let key = state.selectedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, state.selectedKey) : (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate);
64
- if (key) state.setSelectedKey(key);
65
- break;
66
- }
67
- }
68
- };
69
- let { typeSelectProps: typeSelectProps } = (0, $aUnai$useTypeSelect)({
70
- keyboardDelegate: delegate,
71
- selectionManager: state.selectionManager,
72
- onTypeSelect (key) {
73
- state.setSelectedKey(key);
74
- }
75
- });
76
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
77
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $aUnai$useField)({
78
- ...props,
79
- labelElementType: 'span',
80
- isInvalid: isInvalid,
81
- errorMessage: props.errorMessage || validationErrors
82
- });
83
- typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;
84
- delete typeSelectProps.onKeyDownCapture;
85
- if (state.selectionManager.selectionMode === 'multiple') typeSelectProps = {};
86
- let domProps = (0, $aUnai$filterDOMProps)(props, {
87
- labelable: true
88
- });
89
- let triggerProps = (0, $aUnai$mergeProps)(typeSelectProps, menuTriggerProps, fieldProps);
90
- let valueId = (0, $aUnai$useId)();
91
- $58aed456727eb0f3$export$703601b7e90536f8.set(state, {
92
- isDisabled: isDisabled,
93
- isRequired: isRequired,
94
- name: name,
95
- form: form,
96
- validationBehavior: validationBehavior
97
- });
98
- return {
99
- labelProps: {
100
- ...labelProps,
101
- onClick: ()=>{
102
- if (!props.isDisabled) {
103
- var _ref_current;
104
- (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
105
- // Show the focus ring so the user knows where focus went
106
- (0, $aUnai$setInteractionModality)('keyboard');
107
- }
108
- }
109
- },
110
- triggerProps: (0, $aUnai$mergeProps)(domProps, {
111
- ...triggerProps,
112
- isDisabled: isDisabled,
113
- onKeyDown: (0, $aUnai$chain)(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),
114
- onKeyUp: props.onKeyUp,
115
- 'aria-labelledby': [
116
- valueId,
117
- triggerProps['aria-labelledby'],
118
- triggerProps['aria-label'] && !triggerProps['aria-labelledby'] ? triggerProps.id : null
119
- ].filter(Boolean).join(' '),
120
- onFocus (e) {
121
- if (state.isFocused) return;
122
- if (props.onFocus) props.onFocus(e);
123
- if (props.onFocusChange) props.onFocusChange(true);
124
- state.setFocused(true);
125
- },
126
- onBlur (e) {
127
- if (state.isOpen) return;
128
- if (props.onBlur) props.onBlur(e);
129
- if (props.onFocusChange) props.onFocusChange(false);
130
- state.setFocused(false);
131
- }
132
- }),
133
- valueProps: {
134
- id: valueId
135
- },
136
- menuProps: {
137
- ...menuProps,
138
- autoFocus: state.focusStrategy || true,
139
- shouldSelectOnPressUp: true,
140
- shouldFocusOnHover: true,
141
- disallowEmptySelection: true,
142
- linkBehavior: 'selection',
143
- onBlur: (e)=>{
144
- if ((0, $aUnai$nodeContains)(e.currentTarget, e.relatedTarget)) return;
145
- if (props.onBlur) props.onBlur(e);
146
- if (props.onFocusChange) props.onFocusChange(false);
147
- state.setFocused(false);
148
- },
149
- 'aria-labelledby': [
150
- fieldProps['aria-labelledby'],
151
- triggerProps['aria-label'] && !fieldProps['aria-labelledby'] ? triggerProps.id : null
152
- ].filter(Boolean).join(' ')
153
- },
154
- descriptionProps: descriptionProps,
155
- errorMessageProps: errorMessageProps,
156
- isInvalid: isInvalid,
157
- validationErrors: validationErrors,
158
- validationDetails: validationDetails,
159
- hiddenSelectProps: {
160
- isDisabled: isDisabled,
161
- name: name,
162
- label: props.label,
163
- state: state,
164
- triggerRef: ref,
165
- form: form
166
- }
167
- };
168
- }
169
-
170
-
171
- export {$58aed456727eb0f3$export$703601b7e90536f8 as selectData, $58aed456727eb0f3$export$e64b2f635402ca43 as useSelect};
172
- //# sourceMappingURL=useSelect.module.js.map
@@ -1,172 +0,0 @@
1
- import {filterDOMProps as $aUnai$filterDOMProps, mergeProps as $aUnai$mergeProps, useId as $aUnai$useId, chain as $aUnai$chain, nodeContains as $aUnai$nodeContains} from "@react-aria/utils";
2
- import {useMemo as $aUnai$useMemo} from "react";
3
- import {ListKeyboardDelegate as $aUnai$ListKeyboardDelegate, useTypeSelect as $aUnai$useTypeSelect} from "@react-aria/selection";
4
- import {setInteractionModality as $aUnai$setInteractionModality} from "@react-aria/interactions";
5
- import {useCollator as $aUnai$useCollator} from "@react-aria/i18n";
6
- import {useField as $aUnai$useField} from "@react-aria/label";
7
- import {useMenuTrigger as $aUnai$useMenuTrigger} from "@react-aria/menu";
8
-
9
- /*
10
- * Copyright 2020 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
-
21
-
22
-
23
-
24
-
25
-
26
- const $58aed456727eb0f3$export$703601b7e90536f8 = new WeakMap();
27
- function $58aed456727eb0f3$export$e64b2f635402ca43(props, state, ref) {
28
- let { keyboardDelegate: keyboardDelegate, isDisabled: isDisabled, isRequired: isRequired, name: name, form: form, validationBehavior: validationBehavior = 'aria' } = props;
29
- // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
30
- // When virtualized, the layout object will be passed in as a prop and override this.
31
- let collator = (0, $aUnai$useCollator)({
32
- usage: 'search',
33
- sensitivity: 'base'
34
- });
35
- let delegate = (0, $aUnai$useMemo)(()=>keyboardDelegate || new (0, $aUnai$ListKeyboardDelegate)(state.collection, state.disabledKeys, ref, collator), [
36
- keyboardDelegate,
37
- state.collection,
38
- state.disabledKeys,
39
- collator,
40
- ref
41
- ]);
42
- let { menuTriggerProps: menuTriggerProps, menuProps: menuProps } = (0, $aUnai$useMenuTrigger)({
43
- isDisabled: isDisabled,
44
- type: 'listbox'
45
- }, state, ref);
46
- let onKeyDown = (e)=>{
47
- if (state.selectionManager.selectionMode === 'multiple') return;
48
- switch(e.key){
49
- case 'ArrowLeft':
50
- {
51
- var _delegate_getKeyAbove, _delegate_getFirstKey;
52
- // prevent scrolling containers
53
- e.preventDefault();
54
- let key = state.selectedKey != null ? (_delegate_getKeyAbove = delegate.getKeyAbove) === null || _delegate_getKeyAbove === void 0 ? void 0 : _delegate_getKeyAbove.call(delegate, state.selectedKey) : (_delegate_getFirstKey = delegate.getFirstKey) === null || _delegate_getFirstKey === void 0 ? void 0 : _delegate_getFirstKey.call(delegate);
55
- if (key) state.setSelectedKey(key);
56
- break;
57
- }
58
- case 'ArrowRight':
59
- {
60
- var _delegate_getKeyBelow, _delegate_getFirstKey1;
61
- // prevent scrolling containers
62
- e.preventDefault();
63
- let key = state.selectedKey != null ? (_delegate_getKeyBelow = delegate.getKeyBelow) === null || _delegate_getKeyBelow === void 0 ? void 0 : _delegate_getKeyBelow.call(delegate, state.selectedKey) : (_delegate_getFirstKey1 = delegate.getFirstKey) === null || _delegate_getFirstKey1 === void 0 ? void 0 : _delegate_getFirstKey1.call(delegate);
64
- if (key) state.setSelectedKey(key);
65
- break;
66
- }
67
- }
68
- };
69
- let { typeSelectProps: typeSelectProps } = (0, $aUnai$useTypeSelect)({
70
- keyboardDelegate: delegate,
71
- selectionManager: state.selectionManager,
72
- onTypeSelect (key) {
73
- state.setSelectedKey(key);
74
- }
75
- });
76
- let { isInvalid: isInvalid, validationErrors: validationErrors, validationDetails: validationDetails } = state.displayValidation;
77
- let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $aUnai$useField)({
78
- ...props,
79
- labelElementType: 'span',
80
- isInvalid: isInvalid,
81
- errorMessage: props.errorMessage || validationErrors
82
- });
83
- typeSelectProps.onKeyDown = typeSelectProps.onKeyDownCapture;
84
- delete typeSelectProps.onKeyDownCapture;
85
- if (state.selectionManager.selectionMode === 'multiple') typeSelectProps = {};
86
- let domProps = (0, $aUnai$filterDOMProps)(props, {
87
- labelable: true
88
- });
89
- let triggerProps = (0, $aUnai$mergeProps)(typeSelectProps, menuTriggerProps, fieldProps);
90
- let valueId = (0, $aUnai$useId)();
91
- $58aed456727eb0f3$export$703601b7e90536f8.set(state, {
92
- isDisabled: isDisabled,
93
- isRequired: isRequired,
94
- name: name,
95
- form: form,
96
- validationBehavior: validationBehavior
97
- });
98
- return {
99
- labelProps: {
100
- ...labelProps,
101
- onClick: ()=>{
102
- if (!props.isDisabled) {
103
- var _ref_current;
104
- (_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.focus();
105
- // Show the focus ring so the user knows where focus went
106
- (0, $aUnai$setInteractionModality)('keyboard');
107
- }
108
- }
109
- },
110
- triggerProps: (0, $aUnai$mergeProps)(domProps, {
111
- ...triggerProps,
112
- isDisabled: isDisabled,
113
- onKeyDown: (0, $aUnai$chain)(triggerProps.onKeyDown, onKeyDown, props.onKeyDown),
114
- onKeyUp: props.onKeyUp,
115
- 'aria-labelledby': [
116
- valueId,
117
- triggerProps['aria-labelledby'],
118
- triggerProps['aria-label'] && !triggerProps['aria-labelledby'] ? triggerProps.id : null
119
- ].filter(Boolean).join(' '),
120
- onFocus (e) {
121
- if (state.isFocused) return;
122
- if (props.onFocus) props.onFocus(e);
123
- if (props.onFocusChange) props.onFocusChange(true);
124
- state.setFocused(true);
125
- },
126
- onBlur (e) {
127
- if (state.isOpen) return;
128
- if (props.onBlur) props.onBlur(e);
129
- if (props.onFocusChange) props.onFocusChange(false);
130
- state.setFocused(false);
131
- }
132
- }),
133
- valueProps: {
134
- id: valueId
135
- },
136
- menuProps: {
137
- ...menuProps,
138
- autoFocus: state.focusStrategy || true,
139
- shouldSelectOnPressUp: true,
140
- shouldFocusOnHover: true,
141
- disallowEmptySelection: true,
142
- linkBehavior: 'selection',
143
- onBlur: (e)=>{
144
- if ((0, $aUnai$nodeContains)(e.currentTarget, e.relatedTarget)) return;
145
- if (props.onBlur) props.onBlur(e);
146
- if (props.onFocusChange) props.onFocusChange(false);
147
- state.setFocused(false);
148
- },
149
- 'aria-labelledby': [
150
- fieldProps['aria-labelledby'],
151
- triggerProps['aria-label'] && !fieldProps['aria-labelledby'] ? triggerProps.id : null
152
- ].filter(Boolean).join(' ')
153
- },
154
- descriptionProps: descriptionProps,
155
- errorMessageProps: errorMessageProps,
156
- isInvalid: isInvalid,
157
- validationErrors: validationErrors,
158
- validationDetails: validationDetails,
159
- hiddenSelectProps: {
160
- isDisabled: isDisabled,
161
- name: name,
162
- label: props.label,
163
- state: state,
164
- triggerRef: ref,
165
- form: form
166
- }
167
- };
168
- }
169
-
170
-
171
- export {$58aed456727eb0f3$export$703601b7e90536f8 as selectData, $58aed456727eb0f3$export$e64b2f635402ca43 as useSelect};
172
- //# sourceMappingURL=useSelect.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AAuDM,MAAM,4CAAyD,IAAI;AAQnE,SAAS,0CAAiD,KAA8B,EAAE,KAAwB,EAAE,GAAkC;IAC3J,IAAI,oBACF,gBAAgB,cAChB,UAAU,cACV,UAAU,QACV,IAAI,QACJ,IAAI,sBACJ,qBAAqB,QACtB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,oBAAoB,IAAI,CAAA,GAAA,2BAAmB,EAAE,MAAM,UAAU,EAAE,MAAM,YAAY,EAAE,KAAK,WAAW;QAAC;QAAkB,MAAM,UAAU;QAAE,MAAM,YAAY;QAAE;QAAU;KAAI;IAEvM,IAAI,oBAAC,gBAAgB,aAAE,SAAS,EAAC,GAAG,CAAA,GAAA,qBAAa,EAC/C;oBACE;QACA,MAAM;IACR,GACA,OACA;IAGF,IAAI,YAAY,CAAC;QACf,IAAI,MAAM,gBAAgB,CAAC,aAAa,KAAK,YAC3C;QAGF,OAAQ,EAAE,GAAG;YACX,KAAK;gBAAa;wBAIsB,uBAA4C;oBAHlF,+BAA+B;oBAC/B,EAAE,cAAc;oBAEhB,IAAI,MAAM,MAAM,WAAW,IAAI,QAAO,wBAAA,SAAS,WAAW,cAApB,4CAAA,2BAAA,UAAuB,MAAM,WAAW,KAAI,wBAAA,SAAS,WAAW,cAApB,4CAAA,2BAAA;oBAClF,IAAI,KACF,MAAM,cAAc,CAAC;oBAEvB;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,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, SelectionMode} from '@react-types/select';\nimport {chain, filterDOMProps, mergeProps, nodeContains, 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, M extends SelectionMode = 'single'> extends Omit<AriaSelectProps<T, M>, '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, M extends SelectionMode = 'single'> 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, M>\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, 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, M extends SelectionMode = 'single'>(props: AriaSelectOptions<T, M>, state: SelectState<T, M>, ref: RefObject<HTMLElement | null>): SelectAria<T, M> {\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 if (state.selectionManager.selectionMode === 'multiple') {\n return;\n }\n \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 if (state.selectionManager.selectionMode === 'multiple') {\n typeSelectProps = {};\n }\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 (nodeContains(e.currentTarget, 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"}
@@ -1,224 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {FocusableElement, Key, RefObject} from '@react-types/shared';
14
- import {getEventTarget, useFormReset} from '@react-aria/utils';
15
- import React, {InputHTMLAttributes, JSX, ReactNode, useCallback, useRef} from 'react';
16
- import {selectData} from './useSelect';
17
- import {SelectionMode} from '@react-types/select';
18
- import {SelectState} from '@react-stately/select';
19
- import {useFormValidation} from '@react-aria/form';
20
- import {useVisuallyHidden} from '@react-aria/visually-hidden';
21
-
22
- export interface AriaHiddenSelectProps {
23
- /**
24
- * 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).
25
- */
26
- autoComplete?: string,
27
-
28
- /** The text label for the select. */
29
- label?: ReactNode,
30
-
31
- /** HTML form input name. */
32
- name?: string,
33
-
34
- /**
35
- * The `<form>` element to associate the input with.
36
- * The value of this attribute must be the id of a `<form>` in the same document.
37
- * See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form).
38
- */
39
- form?: string,
40
-
41
- /** Sets the disabled state of the select and input. */
42
- isDisabled?: boolean
43
- }
44
-
45
- export interface HiddenSelectProps<T, M extends SelectionMode = 'single'> extends AriaHiddenSelectProps {
46
- /** State for the select. */
47
- state: SelectState<T, M>,
48
-
49
- /** A ref to the trigger element. */
50
- triggerRef: RefObject<FocusableElement | null>
51
- }
52
-
53
- export interface AriaHiddenSelectOptions extends AriaHiddenSelectProps {
54
- /** A ref to the hidden `<select>` element. */
55
- selectRef?: RefObject<HTMLSelectElement | HTMLInputElement | null>
56
- }
57
-
58
- export interface HiddenSelectAria {
59
- /** Props for the container element. */
60
- containerProps: React.HTMLAttributes<FocusableElement>,
61
-
62
- /** Props for the hidden input element. */
63
- inputProps: React.InputHTMLAttributes<HTMLInputElement>,
64
-
65
- /** Props for the hidden select element. */
66
- selectProps: React.SelectHTMLAttributes<HTMLSelectElement>
67
- }
68
-
69
- /**
70
- * Provides the behavior and accessibility implementation for a hidden `<select>` element, which
71
- * can be used in combination with `useSelect` to support browser form autofill, mobile form
72
- * navigation, and native HTML form submission.
73
- */
74
- export function useHiddenSelect<T, M extends SelectionMode = 'single'>(props: AriaHiddenSelectOptions, state: SelectState<T, M>, triggerRef: RefObject<FocusableElement | null>): HiddenSelectAria {
75
- let data = selectData.get(state) || {};
76
- let {autoComplete, name = data.name, form = data.form, isDisabled = data.isDisabled} = props;
77
- let {validationBehavior, isRequired} = data;
78
- let {visuallyHiddenProps} = useVisuallyHidden({
79
- style: {
80
- // Prevent page scrolling.
81
- position: 'fixed',
82
- top: 0,
83
- left: 0
84
- }
85
- });
86
-
87
- useFormReset(props.selectRef, state.defaultValue, state.setValue);
88
- useFormValidation({
89
- validationBehavior,
90
- focus: () => triggerRef.current?.focus()
91
- }, state, props.selectRef);
92
-
93
- let setValue = state.setValue;
94
- let onChange = useCallback((e: React.ChangeEvent<HTMLSelectElement>) => {
95
- let eventTarget = getEventTarget(e);
96
- if (eventTarget.multiple) {
97
- setValue(Array.from(
98
- eventTarget.selectedOptions,
99
- (option) => option.value
100
- ) as any);
101
- } else {
102
- setValue(e.currentTarget.value as any);
103
- }
104
- }, [setValue]);
105
-
106
- // In Safari, the <select> cannot have `display: none` or `hidden` for autofill to work.
107
- // In Firefox, there must be a <label> to identify the <select> whereas other browsers
108
- // seem to identify it just by surrounding text.
109
- // The solution is to use <VisuallyHidden> to hide the elements, which clips the elements to a
110
- // 1px rectangle. In addition, we hide from screen readers with aria-hidden, and make the <select>
111
- // non tabbable with tabIndex={-1}.
112
- return {
113
- containerProps: {
114
- ...visuallyHiddenProps,
115
- 'aria-hidden': true,
116
- // @ts-ignore
117
- ['data-react-aria-prevent-focus']: true,
118
- // @ts-ignore
119
- ['data-a11y-ignore']: 'aria-hidden-focus'
120
- },
121
- inputProps: {
122
- style: {display: 'none'}
123
- },
124
- selectProps: {
125
- tabIndex: -1,
126
- autoComplete,
127
- disabled: isDisabled,
128
- multiple: state.selectionManager.selectionMode === 'multiple',
129
- required: validationBehavior === 'native' && isRequired,
130
- name,
131
- form,
132
- value: (state.value as string | string[]) ?? '',
133
- onChange,
134
- onInput: onChange
135
- }
136
- };
137
- }
138
-
139
- /**
140
- * Renders a hidden native `<select>` element, which can be used to support browser
141
- * form autofill, mobile form navigation, and native form submission.
142
- */
143
- export function HiddenSelect<T, M extends SelectionMode = 'single'>(props: HiddenSelectProps<T, M>): JSX.Element | null {
144
- let {state, triggerRef, label, name, form, isDisabled} = props;
145
- let selectRef = useRef(null);
146
- let inputRef = useRef(null);
147
- let {containerProps, selectProps} = useHiddenSelect({...props, selectRef: state.collection.size <= 300 ? selectRef : inputRef}, state, triggerRef);
148
-
149
- let values: (Key | null)[] = Array.isArray(state.value) ? state.value : [state.value];
150
-
151
- // If used in a <form>, use a hidden input so the value can be submitted to a server.
152
- // If the collection isn't too big, use a hidden <select> element for this so that browser
153
- // autofill will work. Otherwise, use an <input type="hidden">.
154
- if (state.collection.size <= 300) {
155
- return (
156
- <div {...containerProps} data-testid="hidden-select-container">
157
- <label>
158
- {label}
159
- <select {...selectProps} ref={selectRef}>
160
- <option />
161
- {[...state.collection.getKeys()].map(key => {
162
- let item = state.collection.getItem(key);
163
- if (item && item.type === 'item') {
164
- return (
165
- <option
166
- key={item.key}
167
- value={item.key}>
168
- {item.textValue}
169
- </option>
170
- );
171
- }
172
- })}
173
- {/* The collection may be empty during the initial render. */}
174
- {/* Rendering options for the current values ensures the select has a value immediately, */}
175
- {/* making FormData reads consistent. */}
176
- {state.collection.size === 0 && name && values.map((value, i) => <option key={i} value={value ?? ''} />)}
177
- </select>
178
- </label>
179
- </div>
180
- );
181
- } else if (name) {
182
- let data = selectData.get(state) || {};
183
- let {validationBehavior} = data;
184
-
185
- // Always render at least one hidden input to ensure required form submission.
186
- if (values.length === 0) {
187
- values = [null];
188
- }
189
-
190
- let res = values.map((value, i) => {
191
- let inputProps: InputHTMLAttributes<HTMLInputElement> = {
192
- type: 'hidden',
193
- autoComplete: selectProps.autoComplete,
194
- name,
195
- form,
196
- disabled: isDisabled,
197
- value: value ?? ''
198
- };
199
-
200
- if (validationBehavior === 'native') {
201
- // Use a hidden <input type="text"> rather than <input type="hidden">
202
- // so that an empty value blocks HTML form submission when the field is required.
203
- return (
204
- <input
205
- key={i}
206
- {...inputProps}
207
- ref={i === 0 ? inputRef : null}
208
- style={{display: 'none'}}
209
- type="text"
210
- required={i === 0 ? selectProps.required : false}
211
- onChange={() => {/** Ignore react warning. */}} />
212
- );
213
- }
214
-
215
- return (
216
- <input key={i} {...inputProps} ref={i === 0 ? inputRef : null} />
217
- );
218
- });
219
-
220
- return <>{res}</>;
221
- }
222
-
223
- return null;
224
- }