| 1 |
import { useRef, useState } from 'react'; |
| 2 |
import { SearchInput, Button } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const SearchInputFocusSearch: React.FunctionComponent = () => { |
| 5 |
const [value, setValue] = useState(''); |
| 6 |
const ref: React.MutableRefObject<HTMLInputElement | null> = useRef(null); |
| 7 |
|
| 8 |
return ( |
| 9 |
<> |
| 10 |
<SearchInput |
| 11 |
ref={ref} |
| 12 |
value={value} |
| 13 |
onChange={(_event, value) => setValue(value)} |
| 14 |
onClear={() => setValue('')} |
| 15 |
aria-label="Search focus using ref example" |
| 16 |
/> |
| 17 |
<Button onClick={() => ref.current && ref.current.focus()}>Focus on the search input</Button> |
| 18 |
</> |
| 19 |
); |
| 20 |
}; |