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

Function ComboBox

packages/react-aria/stories/combobox/example.tsx:25–90  ·  view source on GitHub ↗
(props: AriaComboBoxProps<any>)

Source from the content-addressed store, hash-verified

23import {useOverlay} from '../../src/overlays/useOverlay';
24
25export function ComboBox(props: AriaComboBoxProps<any>): JSX.Element {
26 // Setup filter function and state.
27 let {contains} = useFilter({sensitivity: 'base'});
28 let state = useComboBoxState({...props, defaultFilter: contains});
29
30 // Setup refs and get props for child elements.
31 let buttonRef = React.useRef(null);
32 let inputRef = React.useRef(null);
33 let listBoxRef = React.useRef(null);
34 let popoverRef = React.useRef(null);
35
36 let {
37 buttonProps: triggerProps,
38 inputProps,
39 listBoxProps,
40 labelProps
41 } = useComboBox(
42 {
43 ...props,
44 inputRef,
45 buttonRef,
46 listBoxRef,
47 popoverRef
48 },
49 state
50 );
51
52 // Call useButton to get props for the button element. Alternatively, you can
53 // pass the triggerProps to a separate Button component using useButton
54 // that you might already have in your component library.
55 let {buttonProps} = useButton(triggerProps, buttonRef);
56
57 return (
58 <div style={{display: 'inline-flex', flexDirection: 'column'}}>
59 <label {...labelProps}>{props.label}</label>
60 <div style={{position: 'relative', display: 'inline-block'}}>
61 <input
62 {...inputProps}
63 ref={inputRef}
64 style={{
65 height: 24,
66 boxSizing: 'border-box',
67 marginRight: 0,
68 fontSize: 16
69 }}
70 />
71 <button
72 {...buttonProps}
73 ref={buttonRef}
74 style={{
75 height: 24,
76 marginLeft: 0
77 }}>
78 <span aria-hidden="true" style={{padding: '0 2px'}}>
79
80 </span>
81 </button>
82 {state.isOpen && (

Callers

nothing calls this directly

Calls 4

useFilterFunction · 0.90
useComboBoxStateFunction · 0.90
useComboBoxFunction · 0.90
useButtonFunction · 0.90

Tested by

no test coverage detected