From cfaadcbbe3ef6b57088fa1c87561b1f1b8de382b Mon Sep 17 00:00:00 2001 From: jamal-khey Date: Tue, 31 Dec 2024 09:43:56 +0100 Subject: [PATCH] ignore white spaces in search term (#658) * Enhance ElementSearchInput component with improved filtering of spaces in both ends of the search term --------- Signed-off-by: jamal-khey --- .../elementSearchInput/ElementSearchInput.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx b/src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx index d547d69c..c3880675 100644 --- a/src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx +++ b/src/components/elementSearch/elementSearchInput/ElementSearchInput.tsx @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { Autocomplete, AutocompleteProps, AutocompleteRenderInputParams } from '@mui/material'; +import { Autocomplete, AutocompleteProps, AutocompleteRenderInputParams, createFilterOptions } from '@mui/material'; import { HTMLAttributes, ReactNode, useMemo } from 'react'; import { useIntl } from 'react-intl'; @@ -53,7 +53,15 @@ export function ElementSearchInput(props: Readonly } = props; const intl = useIntl(); - + const filterOptions = useMemo( + () => + createFilterOptions({ + matchFrom: 'any', + trim: true, + ignoreCase: true, + }), + [] + ); const displayedValue = useMemo(() => { if (searchTermDisabled || searchTermDisableReason) { return ( @@ -120,6 +128,7 @@ export function ElementSearchInput(props: Readonly }} disabled={searchTermDisabled} PaperComponent={PaperComponent} + filterOptions={filterOptions} /> ); }