From 2b9aaa9929240989e1b8d22d3da3bcede09db173 Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Fri, 3 Apr 2026 09:49:30 +0100 Subject: [PATCH] feat: enhance search functionality in ComponentsModal with improved UI and state management --- .../Components/Workflow/ComponentsModal.tsx | 64 +++++++++++++++---- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/Common/UI/Components/Workflow/ComponentsModal.tsx b/Common/UI/Components/Workflow/ComponentsModal.tsx index 662be98737..a63bbc4d3a 100644 --- a/Common/UI/Components/Workflow/ComponentsModal.tsx +++ b/Common/UI/Components/Workflow/ComponentsModal.tsx @@ -1,7 +1,6 @@ // Show a large modal full of components. import ErrorMessage from "../ErrorMessage/ErrorMessage"; import Icon from "../Icon/Icon"; -import Input from "../Input/Input"; import SideOver from "../SideOver/SideOver"; import IconProp from "../../../Types/Icon/IconProp"; import ComponentMetadata, { @@ -12,6 +11,7 @@ import React, { FunctionComponent, ReactElement, useEffect, + useRef, useState, } from "react"; @@ -27,6 +27,8 @@ const ComponentsModal: FunctionComponent = ( props: ComponentProps, ): ReactElement => { const [search, setSearch] = useState(""); + const searchInputRef: React.RefObject = + useRef(null); const [components, setComponents] = useState>([]); const [categories, setCategories] = useState>([]); @@ -76,6 +78,12 @@ const ComponentsModal: FunctionComponent = ( ]); }, [search]); + const hasSearchTerm: boolean = search.trim().length > 0; + const totalComponentCount: number = components.length; + const componentTypeLabel: string = `${props.componentsType.toLowerCase()}${ + totalComponentCount === 1 ? "" : "s" + }`; + return ( = ( <>
{/* Search box */} -
-
-
- +
+ +
+
+
-
- { +
+ ) => { setIsSearching(true); - setSearch(text); + setSearch(event.target.value); }} /> +
+

+ {hasSearchTerm + ? `${componentsToShow.length} of ${totalComponentCount} ${componentTypeLabel} shown` + : "Search by title, description, or category."} +

+ + {hasSearchTerm && ( + + )} +