Skip to content

Commit 019b9fd

Browse files
committed
Add clear button to search input
1 parent 1256f0f commit 019b9fd

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/components/SearchBox.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react'
2-
import { Box, TextField, Button } from '@mui/material'
2+
import { Box, TextField, Button, IconButton, InputAdornment } from '@mui/material'
33
import SearchIcon from '@mui/icons-material/Search'
4+
import ClearIcon from '@mui/icons-material/Clear'
45

56
interface SearchBoxProps {
67
onSearch: (query: string) => void
@@ -24,6 +25,21 @@ export function SearchBox({ onSearch }: SearchBoxProps) {
2425
onChange={(e) => setQuery(e.target.value)}
2526
placeholder="Search for movies..."
2627
variant="outlined"
28+
slotProps={{
29+
input: {
30+
endAdornment: query && (
31+
<InputAdornment position="end">
32+
<IconButton
33+
onClick={() => setQuery('')}
34+
edge="end"
35+
size="small"
36+
>
37+
<ClearIcon />
38+
</IconButton>
39+
</InputAdornment>
40+
),
41+
},
42+
}}
2743
/>
2844
<Button
2945
type="submit"

0 commit comments

Comments
 (0)