Skip to content

Commit

Permalink
Restore searchField.focus() function
Browse files Browse the repository at this point in the history
  • Loading branch information
kjirou committed Jun 16, 2021
1 parent 8576717 commit 09189e9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/Searcher.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { KeyboardEvent, VFC } from 'react'
import {
KeyboardEvent,
VFC,
useEffect,
useRef,
} from 'react'

export type FootprintProps = {
highlighted: boolean;
Expand All @@ -12,10 +17,15 @@ export type Props = {
onKeyDown: (event: KeyboardEvent) => void,
}

// TODO: mount 時に focus する。
// TODO: 最大表示件数を設定する。
// TODO: 検索キーワードがマッチしている箇所をハイライトする。
export const Searcher: VFC<Props> = (props) => {
const searchFieldRef = useRef<HTMLInputElement>(null)

useEffect(() => {
searchFieldRef.current?.focus()
}, [])

return <div
style={{
width: '600px',
Expand All @@ -26,6 +36,7 @@ export const Searcher: VFC<Props> = (props) => {
}}
>
<input
ref={searchFieldRef}
onInput={event => {
props.onInput(event.currentTarget.value)
}}
Expand Down

0 comments on commit 09189e9

Please sign in to comment.