Skip to content

Commit

Permalink
fix(search): clearable (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
purusott authored Jun 11, 2024
1 parent df5f0ca commit aef0e13
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions next-tavla/app/(admin)/boards/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@
import { TextField } from '@entur/form'
import { SearchIcon } from '@entur/icons'
import { useSearchParamReplacer } from '../../hooks/useSearchParamReplacer'
import { useEffect, useState } from 'react'

function Search() {
const [value, replace] = useSearchParamReplacer('search')
const [search, setSearch] = useState(value)

useEffect(() => {
replace(search)
}, [replace, search])
return (
<TextField
className="w-full md:w-1/2"
label="Søk på navn på tavle"
prepend={<SearchIcon inline aria-hidden="true" />}
defaultValue={value}
value={search}
onChange={(e) => {
replace(e.target.value)
setSearch(e.target.value)
}}
id="search"
clearable
onClear={() => {
setSearch('')
}}
/>
)
Expand Down

0 comments on commit aef0e13

Please sign in to comment.