()
| 8 | import classes from './SearchTextInput.module.css'; |
| 9 | |
| 10 | const SearchBar = () => { |
| 11 | const { ref, focused } = useFocusWithin(); |
| 12 | const { query, refine } = useSearchBox(); |
| 13 | const [inputValue, setInputValue] = useState(query); |
| 14 | |
| 15 | const handleSearch = useDebouncedCallback((value: string) => { |
| 16 | refine(value); |
| 17 | }, 300); |
| 18 | |
| 19 | const onChange = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 20 | setInputValue(event.currentTarget.value); |
| 21 | handleSearch(event.currentTarget.value); |
| 22 | }; |
| 23 | |
| 24 | // Track when the InstantSearch query changes to synchronize it with |
| 25 | // the React state. |
| 26 | // We bypass the state update if the input is focused to avoid concurrent |
| 27 | // updates when typing. |
| 28 | if (query !== inputValue && !focused) { |
| 29 | setInputValue(query); |
| 30 | } |
| 31 | |
| 32 | return ( |
| 33 | <TextInput |
| 34 | value={inputValue} |
| 35 | onChange={onChange} |
| 36 | placeholder="Search fonts" |
| 37 | aria-label="Search fonts" |
| 38 | variant="unstyled" |
| 39 | // className={classes.wrapper} |
| 40 | classNames={{ |
| 41 | wrapper: classes.wrapper, |
| 42 | input: classes.input, |
| 43 | }} |
| 44 | autoComplete="off" |
| 45 | autoCorrect="off" |
| 46 | spellCheck={false} |
| 47 | maxLength={512} |
| 48 | ref={ref} |
| 49 | leftSection={ |
| 50 | <IconSearch data-active={focused} className={classes.left} /> |
| 51 | } |
| 52 | leftSectionWidth={60} |
| 53 | rightSection={<SearchByAlgolia height={14} />} |
| 54 | rightSectionWidth={100} |
| 55 | /> |
| 56 | ); |
| 57 | }; |
| 58 | |
| 59 | export { SearchBar }; |
nothing calls this directly
no outgoing calls
no test coverage detected