From 65772abf87d02f1a65944172397aa6be26d70641 Mon Sep 17 00:00:00 2001 From: mkljczk Date: Fri, 29 Nov 2024 20:26:50 +0100 Subject: [PATCH] pl-fe: Use icon to indicate that search field value has not been sent Signed-off-by: mkljczk --- .../src/features/search/components/search.tsx | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/pl-fe/src/features/search/components/search.tsx b/packages/pl-fe/src/features/search/components/search.tsx index 2db84c064..342c3c261 100644 --- a/packages/pl-fe/src/features/search/components/search.tsx +++ b/packages/pl-fe/src/features/search/components/search.tsx @@ -1,4 +1,3 @@ -import clsx from 'clsx'; import React, { useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useSearchParams } from 'react-router-dom-v5-compat'; @@ -26,12 +25,16 @@ const Search = () => { setValue(value); }; - const handleClear = (event: React.MouseEvent) => { + const handleClick = (event: React.MouseEvent) => { event.preventDefault(); - if (value.length > 0) { - setValue(''); - setQuery(''); + if (params.get('q') === value) { + if (value.length > 0) { + setValue(''); + setQuery(''); + } + } else { + setQuery(value); } }; @@ -45,8 +48,6 @@ const Search = () => { } }; - const hasValue = value.length > 0; - return (
{ role='button' tabIndex={0} className='absolute inset-y-0 right-0 flex cursor-pointer items-center px-3 rtl:left-0 rtl:right-auto' - onClick={handleClear} + onClick={handleClick} > - + {params.get('q') === value ? ( + + ) : ( + + )} -