[ui][typeahead] add optional minQueryLength parameter

pull/519/head
Yangshun Tay 2 years ago
parent 63b6a61ad3
commit 30c68afed6

@ -41,6 +41,7 @@ export default function CitiesTypeahead({
return ( return (
<Typeahead <Typeahead
label={label} label={label}
minQueryLength={3}
noResultsMessage="No cities found" noResultsMessage="No cities found"
nullable={true} nullable={true}
options={ options={

@ -39,6 +39,7 @@ export default function CountriesTypeahead({
return ( return (
<Typeahead <Typeahead
label="Country" label="Country"
minQueryLength={3}
noResultsMessage="No countries found" noResultsMessage="No countries found"
nullable={true} nullable={true}
options={ options={

@ -28,6 +28,8 @@ type Props = Readonly<{
errorMessage?: React.ReactNode; errorMessage?: React.ReactNode;
isLabelHidden?: boolean; isLabelHidden?: boolean;
label: string; label: string;
// Minimum query length before any results will be shown.
minQueryLength?: number;
noResultsMessage?: string; noResultsMessage?: string;
onQueryChange: ( onQueryChange: (
value: string, value: string,
@ -80,6 +82,7 @@ export default function Typeahead({
errorMessage, errorMessage,
isLabelHidden, isLabelHidden,
label, label,
minQueryLength = 0,
noResultsMessage = 'No results', noResultsMessage = 'No results',
nullable = false, nullable = false,
options, options,
@ -167,6 +170,7 @@ export default function Typeahead({
/> />
</Combobox.Button> </Combobox.Button>
</div> </div>
{query.length >= minQueryLength && (
<Transition <Transition
afterLeave={() => setQuery('')} afterLeave={() => setQuery('')}
as={Fragment} as={Fragment}
@ -207,6 +211,7 @@ export default function Typeahead({
)} )}
</Combobox.Options> </Combobox.Options>
</Transition> </Transition>
)}
</div> </div>
</Combobox> </Combobox>
{errorMessage && ( {errorMessage && (

Loading…
Cancel
Save