Skip to content

Commit

Permalink
Enhance ElementSearchInput component with improved filtering and sear…
Browse files Browse the repository at this point in the history
…ch term handling

Signed-off-by: jamal-khey <[email protected]>
  • Loading branch information
jamal-khey committed Dec 26, 2024
1 parent 1bf129d commit 2fa67fa
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
* 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';

function createGenericFilterOptions<T>() {
return createFilterOptions<T>({
matchFrom: 'any',
trim: true,
ignoreCase: true,
});
}

export type RenderElementProps<T> = HTMLAttributes<HTMLLIElement> & {
element: T;
inputValue: string;
Expand Down Expand Up @@ -53,7 +61,7 @@ export function ElementSearchInput<T>(props: Readonly<ElementSearchInputProps<T>
} = props;

const intl = useIntl();

const filterOptions = useMemo(() => createGenericFilterOptions<T>(), []);
const displayedValue = useMemo(() => {
if (searchTermDisabled || searchTermDisableReason) {
return (
Expand Down Expand Up @@ -120,6 +128,7 @@ export function ElementSearchInput<T>(props: Readonly<ElementSearchInputProps<T>
}}
disabled={searchTermDisabled}
PaperComponent={PaperComponent}
filterOptions={filterOptions}
/>
);
}

0 comments on commit 2fa67fa

Please sign in to comment.