From 30c68afed6f1bb87fa743b14e171076066b001ca Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Sat, 5 Nov 2022 20:09:18 +0800 Subject: [PATCH] [ui][typeahead] add optional minQueryLength parameter --- .../src/components/shared/CitiesTypeahead.tsx | 1 + .../components/shared/CountriesTypeahead.tsx | 1 + packages/ui/src/Typeahead/Typeahead.tsx | 85 ++++++++++--------- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/apps/portal/src/components/shared/CitiesTypeahead.tsx b/apps/portal/src/components/shared/CitiesTypeahead.tsx index 902759b0..f9a6140d 100644 --- a/apps/portal/src/components/shared/CitiesTypeahead.tsx +++ b/apps/portal/src/components/shared/CitiesTypeahead.tsx @@ -41,6 +41,7 @@ export default function CitiesTypeahead({ return ( - setQuery('')} - as={Fragment} - leave="transition ease-in duration-100" - leaveFrom="opacity-100" - leaveTo="opacity-0"> - - {options.length === 0 && query !== '' ? ( -
- {noResultsMessage} -
- ) : ( - options.map((option) => ( - - clsx( - 'relative cursor-default select-none py-2 px-4 text-slate-500', - active && 'bg-slate-100', - ) - } - value={option}> - {({ selected }) => ( - - {option.label} - - )} - - )) - )} -
-
+ {query.length >= minQueryLength && ( + setQuery('')} + as={Fragment} + leave="transition ease-in duration-100" + leaveFrom="opacity-100" + leaveTo="opacity-0"> + + {options.length === 0 && query !== '' ? ( +
+ {noResultsMessage} +
+ ) : ( + options.map((option) => ( + + clsx( + 'relative cursor-default select-none py-2 px-4 text-slate-500', + active && 'bg-slate-100', + ) + } + value={option}> + {({ selected }) => ( + + {option.label} + + )} + + )) + )} +
+
+ )} {errorMessage && (