import { forwardRef } from 'preact/compat'; import { useImperativeHandle, useRef, useState } from 'preact/hooks'; import { useSearchParams } from 'react-router-dom'; import { api } from '../utils/api'; import Icon from './icon'; import Link from './link'; const SearchForm = forwardRef((props, ref) => { const { instance } = api(); const [searchParams, setSearchParams] = useSearchParams(); const [searchMenuOpen, setSearchMenuOpen] = useState(false); const [query, setQuery] = useState(searchParams.get('q') || ''); const type = searchParams.get('type'); const formRef = useRef(null); const searchFieldRef = useRef(null); useImperativeHandle(ref, () => ({ setValue: (value) => { setQuery(value); }, focus: () => { searchFieldRef.current.focus(); }, select: () => { searchFieldRef.current.select(); }, blur: () => { searchFieldRef.current.blur(); }, })); return (
); }); export default SearchForm;