MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useComboBox

Function useComboBox

packages/react-aria/src/combobox/useComboBox.ts:124–550  ·  view source on GitHub ↗
(
  props: AriaComboBoxOptions<T, M>,
  state: ComboBoxState<T, M>
)

Source from the content-addressed store, hash-verified

122 * @param state - State for the select, as returned by `useComboBoxState`.
123 */
124export function useComboBox<T, M extends SelectionMode = 'single'>(
125 props: AriaComboBoxOptions<T, M>,
126 state: ComboBoxState<T, M>
127): ComboBoxAria<T> {
128 let {
129 buttonRef,
130 popoverRef,
131 inputRef,
132 listBoxRef,
133 keyboardDelegate,
134 layoutDelegate,
135 // completionMode = 'suggest',
136 shouldFocusWrap,
137 isReadOnly,
138 isDisabled
139 } = props;
140 let backupBtnRef = useRef(null);
141 buttonRef = buttonRef ?? backupBtnRef;
142
143 let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/combobox');
144 let {menuTriggerProps, menuProps} = useMenuTrigger<T>(
145 {
146 type: 'listbox',
147 isDisabled: isDisabled || isReadOnly
148 },
149 state,
150 buttonRef
151 );
152
153 // Set listbox id so it can be used when calling getItemId later
154 listData.set(state, {id: menuProps.id});
155
156 // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
157 // When virtualized, the layout object will be passed in as a prop and override this.
158 let {collection} = state;
159 let {disabledKeys} = state.selectionManager;
160 let delegate = useMemo(
161 () =>
162 keyboardDelegate ||
163 new ListKeyboardDelegate({
164 collection,
165 disabledKeys,
166 ref: listBoxRef,
167 layoutDelegate
168 }),
169 [keyboardDelegate, layoutDelegate, collection, disabledKeys, listBoxRef]
170 );
171
172 // Use useSelectableCollection to get the keyboard handlers to apply to the textfield
173 let {collectionProps} = useSelectableCollection({
174 selectionManager: state.selectionManager,
175 keyboardDelegate: delegate,
176 disallowTypeAhead: true,
177 disallowEmptySelection: true,
178 shouldFocusWrap,
179 ref: inputRef,
180 // Prevent item scroll behavior from being applied here, should be handled in the user's Popover + ListBox component
181 isVirtualized: true

Callers 7

useSearchAutocompleteFunction · 0.90
ComboBoxFunction · 0.90
ComboBoxInnerFunction · 0.90
ComboBoxTrayFunction · 0.90
ComboBox.tsxFile · 0.90
ComboBoxInnerFunction · 0.90

Calls 15

useMenuTriggerFunction · 0.90
useSelectableCollectionFunction · 0.90
useRouterFunction · 0.90
useKeyboardFunction · 0.90
useTextFieldFunction · 0.90
chainFunction · 0.90
useFormResetFunction · 0.90
useLabelsFunction · 0.90
getChildNodesFunction · 0.90
announceFunction · 0.90
getItemCountFunction · 0.90

Tested by

no test coverage detected