From d82913a45d610fc16201fc0df8a315c4bffcb150 Mon Sep 17 00:00:00 2001 From: "Andy Chan (12beesinatrenchcoat)" Date: Sun, 31 Mar 2024 18:47:12 -0400 Subject: [PATCH] Add non-functional search bar Does not do anything at the moment. --- compass/components/Table/TableAction.tsx | 42 +++++++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) 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()}> + + + +
+ ); +};