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

Function ComboBoxInner

packages/react-aria-components/src/ComboBox.tsx:196–378  ·  view source on GitHub ↗
({props, collection, comboBoxRef: ref}: ComboBoxInnerProps<T>)

Source from the content-addressed store, hash-verified

194}
195
196function ComboBoxInner<T>({props, collection, comboBoxRef: ref}: ComboBoxInnerProps<T>) {
197 let {name, formValue = 'key', allowsCustomValue} = props;
198 if (allowsCustomValue) {
199 formValue = 'text';
200 }
201
202 let {validationBehavior: formValidationBehavior} = useSlottedContext(FormContext) || {};
203 let validationBehavior = props.validationBehavior ?? formValidationBehavior ?? 'native';
204 let {contains} = useFilter({sensitivity: 'base'});
205 let state = useComboBoxState({
206 ...props,
207 defaultFilter: props.defaultFilter || contains,
208 // If props.items isn't provided, rely on collection filtering (aka listbox.items is provided or defaultItems provided to Combobox)
209 items: props.items,
210 children: undefined,
211 collection,
212 validationBehavior
213 });
214
215 let buttonRef = useRef<HTMLButtonElement>(null);
216 let inputRef = useRef<HTMLInputElement>(null);
217 let groupRef = useRef<HTMLDivElement>(null);
218 let listBoxRef = useRef<HTMLDivElement>(null);
219 let popoverRef = useRef<HTMLDivElement>(null);
220 let [labelRef, label] = useSlot(!props['aria-label'] && !props['aria-labelledby']);
221 let [labelElementType, setLabelElementType] = useState<'span' | 'label'>('label');
222
223 let {
224 buttonProps,
225 inputProps,
226 listBoxProps,
227 labelProps,
228 descriptionProps,
229 errorMessageProps,
230 valueProps,
231 ...validation
232 } = useComboBox(
233 {
234 ...removeDataAttributes(props),
235 label,
236 inputRef,
237 buttonRef,
238 listBoxRef,
239 popoverRef,
240 name: formValue === 'text' ? name : undefined,
241 validationBehavior,
242 labelElementType
243 },
244 state
245 );
246
247 // Make menu width match input + button
248 // Left for backward compatibility in case a <Group> is not rendered.
249 let [menuWidth, setMenuWidth] = useState<string | null>(null);
250 let onResize = useCallback(() => {
251 if (inputRef.current && !groupRef.current) {
252 let buttonRect = buttonRef.current?.getBoundingClientRect();
253 let inputRect = inputRef.current.getBoundingClientRect();

Callers

nothing calls this directly

Calls 10

useSlottedContextFunction · 0.90
useFilterFunction · 0.90
useComboBoxStateFunction · 0.90
useSlotFunction · 0.90
useComboBoxFunction · 0.90
removeDataAttributesFunction · 0.90
useResizeObserverFunction · 0.90
useRenderPropsFunction · 0.90
filterDOMPropsFunction · 0.90
setInputValueMethod · 0.65

Tested by

no test coverage detected