diff --git a/compass/components/Table/TableAction.tsx b/compass/components/Table/TableAction.tsx index be4a309..f2a72a0 100644 --- a/compass/components/Table/TableAction.tsx +++ b/compass/components/Table/TableAction.tsx @@ -1,12 +1,36 @@ import { MagnifyingGlassIcon } from "@heroicons/react/24/solid"; +import { useRef, useState } from "react"; export const TableAction = () => { - return ( -
- Filter - Sort - -
- ); - }; - \ No newline at end of file + const searchInput = useRef(null); + const [searchActive, setSearchActive] = useState(false); + const activateSearch = () => { + setSearchActive(true); + if (searchInput.current === null) { return; } + searchInput.current.focus(); + searchInput.current.addEventListener("focusout", () => { + if (searchInput.current?.value.trim() === "") { + searchInput.current.value = ""; + deactivateSearch(); + } + }) + } + + const deactivateSearch = () => setSearchActive(false); + + return ( +
+ Filter + Sort + activateSearch()}> + + + +
+ ); +};