Skip to content

Commit

Permalink
Add reset button to SearchBar (#269)
Browse files Browse the repository at this point in the history
* feat: Add cancel button to search bar for resetting search query

* Format

* Replaced icon

* Update icon

---------

Co-authored-by: Jason Zheng <jasonz4200@gmail.com>
  • Loading branch information
akinfelami and jasozh authored Jun 20, 2024
1 parent 744d717 commit f82633a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions frontend/src/components/atoms/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ChangeEvent, FormEvent } from "react";
import { Box, TextField, InputAdornment, IconButton } from "@mui/material";
import SearchIcon from "@mui/icons-material/Search";
import ClearIcon from "@mui/icons-material/Clear";

interface SearchBarProps {
onSubmit: any;
Expand All @@ -25,6 +26,21 @@ const SearchBar = ({ onSubmit, ...props }: SearchBarProps) => {
InputProps={{
endAdornment: (
<InputAdornment position="end">
{props.showCancelButton && (
<div className="flex flex-row items-center">
<IconButton
type="button"
aria-label="cancel"
edge="end"
onClick={() => {
props.resetSearch();
}}
>
<ClearIcon />
</IconButton>
<div className="ml-3 text-gray-400">|</div>
</div>
)}
<IconButton type="submit" aria-label="search" edge="end">
<SearchIcon />
</IconButton>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/organisms/ManageAttendees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ const AttendeesTable = ({
handleSearchQuery(value);
};

const handleResetSearch = () => {
setValue("");
handleSearchQuery("");
};

return (
<div>
{attendeesStatus === "PENDING" ? (
Expand Down Expand Up @@ -248,6 +253,8 @@ const AttendeesTable = ({
value={value}
onChange={handleChange}
onSubmit={handleSubmit}
resetSearch={handleResetSearch}
showCancelButton={value !== ""}
/>
</div>
<Card size="table">
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/components/organisms/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ const Active = ({
handleNewSearchQuery(value);
};

const handleResetSearch = () => {
setValue("");
handleNewSearchQuery("");
};

return (
<div>
<div className="pb-5 w-full sm:w-[600px]">
Expand All @@ -136,6 +141,8 @@ const Active = ({
value={value}
onChange={handleChange}
onSubmit={handleSubmitSearch}
resetSearch={handleResetSearch}
showCancelButton={value !== ""}
/>
</div>
<Card size="table">
Expand Down Expand Up @@ -247,6 +254,11 @@ const Blacklisted = ({
handleNewSearchQuery(value);
};

const handleResetSearch = () => {
setValue("");
handleNewSearchQuery("");
};

return (
<div>
<div className="pb-5 w-full sm:w-[600px]">
Expand All @@ -255,6 +267,8 @@ const Blacklisted = ({
value={value}
onChange={handleChange}
onSubmit={handleSubmitSearch}
resetSearch={handleResetSearch}
showCancelButton={value !== ""}
/>
</div>
<Card size="table">
Expand Down

0 comments on commit f82633a

Please sign in to comment.