From c18d0f6c131aab8972b24d6b37a5496661adea59 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 8 Aug 2024 15:46:17 +0200 Subject: [PATCH] refactor: use search submit and clean events, instead of change --- src/pages/home/index.tsx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index d728a78..b6a801b 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -149,14 +149,27 @@ export const HomePage = () => { />
-
+
{ + e.preventDefault() + const searchInput = e.currentTarget.elements.namedItem( + 'q' + ) as HTMLInputElement + setSearch(searchInput.value) + }} + > { - setSearch(e.currentTarget.value) - }} size="small" + type="search" + onChange={(e) => { + // Handle the case when users click native search input's clear or x + if (e.currentTarget.value === '') { + setSearch(e.currentTarget.value) + } + }} sx={{ width: '100%', fontSize: '16px', @@ -175,6 +188,7 @@ export const HomePage = () => { }} /> -
+