diff --git a/src/Components/Search.jsx b/src/Components/Search.jsx index a8bfead..06e3433 100644 --- a/src/Components/Search.jsx +++ b/src/Components/Search.jsx @@ -1,4 +1,4 @@ -import React, {useState} from 'react'; +import React, {useEffect, useState} from 'react'; import { subMenusList } from '../Constants'; import {CiSearch } from "react-icons/ci"; import { AiOutlineDoubleRight } from "react-icons/ai"; @@ -6,6 +6,7 @@ import { NavLink } from 'react-router-dom'; const Search = () => { const [searchInput, setSearchInput] = useState(""); + const [isSearchBarOpen, setIsSearchBarOpen] = useState(false); const handleChange = (e) => { e.preventDefault(); setSearchInput(e.target.value); @@ -13,7 +14,17 @@ const Search = () => { const filteredContent = subMenusList.filter(menu => { const content = menu.title.toLowerCase(); return content.includes(searchInput.toLowerCase()); - }) + }); + + const selectOption = (name) => { + setSearchInput(name); + setIsSearchBarOpen(false) + }; + + // useEffect(() => { + // setSearchInput(""); + // },[selectOption]) + return ( <>
@@ -25,13 +36,13 @@ const Search = () => { onChange={handleChange} value={searchInput} />
- {searchInput && ( -
+ {(searchInput && !isSearchBarOpen) && ( +
{filteredContent.map((menu,i) => ( menu.children.map(child => (
-

{menu.name}

+

selectOption(menu.name)}>{menu.name}

)) diff --git a/src/layouts/sidebar/SubMenu.jsx b/src/layouts/sidebar/SubMenu.jsx index 40de7cd..3bd67ee 100644 --- a/src/layouts/sidebar/SubMenu.jsx +++ b/src/layouts/sidebar/SubMenu.jsx @@ -12,7 +12,7 @@ const SubMenu = ({ data }) => { return ( <>
  • setSubMenuOpen(!subMenuOpen)} > {/* */}