aboutsummaryrefslogtreecommitdiff
path: root/vnext/src/ui/SearchBox.js
blob: 636967b13d7b4c8ccd7693edf58e1b4020f31f24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { useForm } from 'react-hook-form';

/**
 * @typedef {object} SearchBoxPropsFields
 * @property {Function} onSearch
 */

/**
 * @typedef {SearchBoxPropsFields} SearchBoxProps
 */

/**
 * @param {SearchBoxProps} props
 */
function SearchBox({ onSearch }) {
    const { register, handleSubmit } = useForm();
    /** @type { import('react-hook-form').SubmitHandler<import('react-hook-form').FieldValues> } */
    let onSubmit = ( values ) => {
        onSearch(values.search);
    };
    return (
        <form onSubmit={handleSubmit(onSubmit)}>
            <input className="text" type="text"
                placeholder="Search..." {...register('search')} />
            <input data-testid="submit" type="submit" hidden />
        </form>
    );
}

export default SearchBox;