UI: search bar improvement. Bug: ESC doesnt work
This commit is contained in:
@@ -33,12 +33,13 @@ export function SearchBar(props: SearchBarProps) {
|
|||||||
const debouncedSearch = useDebounce(search, 250);
|
const debouncedSearch = useDebounce(search, 250);
|
||||||
|
|
||||||
// Define a function to handle the Esc key press
|
// Define a function to handle the Esc key press
|
||||||
const handleEsc = (event: any) => {
|
function handleEsc(event: React.KeyboardEvent<HTMLDivElement>) {
|
||||||
if (event.key === "Escape") {
|
if (event.key === "Escape") {
|
||||||
|
console.log("Escape key pressed");
|
||||||
setSearch("");
|
setSearch("");
|
||||||
setFilteredList(tableData);
|
setFilteredList(tableData);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (debouncedSearch) {
|
if (debouncedSearch) {
|
||||||
@@ -65,6 +66,7 @@ export function SearchBar(props: SearchBarProps) {
|
|||||||
<Autocomplete
|
<Autocomplete
|
||||||
freeSolo
|
freeSolo
|
||||||
options={suggestions}
|
options={suggestions}
|
||||||
|
onKeyDown={handleEsc}
|
||||||
onChange={(event, value) => {
|
onChange={(event, value) => {
|
||||||
// do something with the selected value
|
// do something with the selected value
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
@@ -81,18 +83,17 @@ export function SearchBar(props: SearchBarProps) {
|
|||||||
label="Search"
|
label="Search"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={search}
|
value={search}
|
||||||
onKeyDown={handleEsc}
|
|
||||||
onChange={handleInputChange}
|
onChange={handleInputChange}
|
||||||
autoComplete="nickname"
|
autoComplete="nickname"
|
||||||
InputProps={{
|
InputProps={{
|
||||||
...params.InputProps,
|
...params.InputProps,
|
||||||
endAdornment: (
|
// endAdornment: (
|
||||||
<InputAdornment position="end">
|
// <InputAdornment position="end">
|
||||||
<IconButton>
|
// <IconButton>
|
||||||
<SearchIcon />
|
// <SearchIcon />
|
||||||
</IconButton>
|
// </IconButton>
|
||||||
</InputAdornment>
|
// </InputAdornment>
|
||||||
),
|
// ),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* {suggestions.map((item, index) => (
|
{/* {suggestions.map((item, index) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user