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

Function SearchField

starters/hooks/src/SearchField.tsx:16–44  ·  view source on GitHub ↗
(props: SearchFieldProps)

Source from the content-addressed store, hash-verified

14}
15
16export function SearchField(props: SearchFieldProps) {
17 let state = useSearchFieldState(props);
18 let ref = useRef<HTMLInputElement>(null);
19 /*- begin highlight -*/
20 let {labelProps, inputProps, clearButtonProps} = useSearchField(props, state, ref);
21 /*- end highlight -*/
22 let [isFocused, setFocused] = useState(false);
23 let {focusProps} = useFocus({onFocusChange: setFocused});
24
25 return (
26 <div className="react-aria-SearchField" data-empty={state.value === '' || undefined}>
27 {props.label && (
28 <label className="react-aria-Label" {...labelProps}>
29 {props.label}
30 </label>
31 )}
32 <Search size={18} aria-hidden="true" />
33 <input
34 {...mergeProps(inputProps, focusProps)}
35 ref={ref}
36 className="react-aria-Input inset"
37 data-focused={isFocused || undefined}
38 />
39 <ClearButton {...clearButtonProps}>
40 <X size={14} />
41 </ClearButton>
42 </div>
43 );
44}
45
46function ClearButton(props: AriaButtonProps) {
47 let ref = useRef<HTMLButtonElement>(null);

Callers

nothing calls this directly

Calls 4

useSearchFieldStateFunction · 0.90
useSearchFieldFunction · 0.90
useFocusFunction · 0.90
mergePropsFunction · 0.90

Tested by

no test coverage detected