node/@patternfly/react-core/src/components/TextInput/examples/TextInputSelectUsingRef.tsx
raw| 1 | import { useRef, useState } from 'react'; |
| 2 | import { TextInput } from '@patternfly/react-core'; |
| 3 | |
| 4 | export const TextInputSelectUsingRef: React.FunctionComponent = () => { |
| 5 | const [value, setValue] = useState('select all on click'); |
| 6 | const ref = useRef<HTMLInputElement>(null); |
| 7 | return ( |
| 8 | <TextInput |
| 9 | ref={ref} |
| 10 | value={value} |
| 11 | onFocus={() => ref?.current?.select()} |
| 12 | onChange={(_event, value) => setValue(value)} |
| 13 | aria-label="select-all" |
| 14 | /> |
| 15 | ); |
| 16 | }; |