MCPcopy
hub / github.com/adobe/react-spectrum / Select

Function Select

packages/react-aria/stories/select/example.tsx:25–59  ·  view source on GitHub ↗
(props: AriaSelectProps<T>)

Source from the content-addressed store, hash-verified

23import {useSelectState} from 'react-stately/useSelectState';
24
25export function Select<T extends object>(props: AriaSelectProps<T>): JSX.Element {
26 // Create state based on the incoming props
27 let state = useSelectState(props);
28
29 // Get props for child elements from useSelect
30 let ref = React.useRef(null);
31 let {labelProps, triggerProps, valueProps, menuProps, hiddenSelectProps} = useSelect(
32 props,
33 state,
34 ref
35 );
36
37 // Get props for the button based on the trigger props from useSelect
38 let {buttonProps} = useButton(triggerProps, ref);
39
40 return (
41 <div style={{position: 'relative', display: 'inline-block'}}>
42 <div {...labelProps}>{props.label}</div>
43 <HiddenSelect {...hiddenSelectProps} />
44 <button {...buttonProps} ref={ref} style={{height: 30, fontSize: 14}}>
45 <span {...valueProps}>
46 {state.selectedItem ? state.selectedItem.rendered : 'Select an option'}
47 </span>
48 <span aria-hidden="true" style={{paddingLeft: 5}}>
49
50 </span>
51 </button>
52 {state.isOpen && (
53 <Popover isOpen={state.isOpen} onClose={state.close}>
54 <ListBox {...menuProps} state={state} />
55 </Popover>
56 )}
57 </div>
58 );
59}
60
61function Popover(props) {
62 let ref = React.useRef(undefined);

Callers

nothing calls this directly

Calls 3

useSelectStateFunction · 0.90
useSelectFunction · 0.90
useButtonFunction · 0.90

Tested by

no test coverage detected