[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 (
<Typeahead
label={label}
minQueryLength={3}
noResultsMessage="No cities found"
nullable={true}
options={

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

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

Loading…
Cancel
Save