MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useSelect

Function useSelect

packages/react-aria/src/select/useSelect.ts:113–309  ·  view source on GitHub ↗
(
  props: AriaSelectOptions<T, M>,
  state: SelectState<T, M>,
  ref: RefObject<HTMLElement | null>
)

Source from the content-addressed store, hash-verified

111 * @param state - State for the select, as returned by `useListState`.
112 */
113export function useSelect<T, M extends SelectionMode = 'single'>(
114 props: AriaSelectOptions<T, M>,
115 state: SelectState<T, M>,
116 ref: RefObject<HTMLElement | null>
117): SelectAria<T, M> {
118 let {keyboardDelegate, isDisabled, isRequired, name, form, validationBehavior = 'aria'} = props;
119
120 // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
121 // When virtualized, the layout object will be passed in as a prop and override this.
122 let collator = useCollator({usage: 'search', sensitivity: 'base'});
123 let delegate = useMemo(
124 () =>
125 keyboardDelegate ||
126 new ListKeyboardDelegate(state.collection, state.disabledKeys, ref, collator),
127 [keyboardDelegate, state.collection, state.disabledKeys, collator, ref]
128 );
129
130 let {menuTriggerProps, menuProps} = useMenuTrigger<T>(
131 {
132 isDisabled,
133 type: 'listbox'
134 },
135 state,
136 ref
137 );
138
139 let onKeyDown = (e: KeyboardEvent) => {
140 if (state.selectionManager.selectionMode === 'multiple') {
141 return;
142 }
143
144 switch (e.key) {
145 case 'ArrowLeft': {
146 // prevent scrolling containers
147 e.preventDefault();
148
149 let key =
150 state.selectedKey != null
151 ? delegate.getKeyAbove?.(state.selectedKey)
152 : delegate.getFirstKey?.();
153 if (key != null) {
154 state.setSelectedKey(key);
155 }
156 break;
157 }
158 case 'ArrowRight': {
159 // prevent scrolling containers
160 e.preventDefault();
161
162 let key =
163 state.selectedKey != null
164 ? delegate.getKeyBelow?.(state.selectedKey)
165 : delegate.getFirstKey?.();
166 if (key != null) {
167 state.setSelectedKey(key);
168 }
169 break;
170 }

Callers 3

SelectFunction · 0.90
SelectInnerFunction · 0.90
Picker.tsxFile · 0.90

Calls 15

useCollatorFunction · 0.90
useMenuTriggerFunction · 0.90
useTypeSelectFunction · 0.90
useFieldFunction · 0.90
filterDOMPropsFunction · 0.90
mergePropsFunction · 0.90
useIdFunction · 0.90
setInteractionModalityFunction · 0.90
chainFunction · 0.90
nodeContainsFunction · 0.90
focusMethod · 0.80
onBlurMethod · 0.80

Tested by

no test coverage detected