diff --git a/packages/ui/src/Typeahead/Typeahead.tsx b/packages/ui/src/Typeahead/Typeahead.tsx index b2967f6d..c0e91672 100644 --- a/packages/ui/src/Typeahead/Typeahead.tsx +++ b/packages/ui/src/Typeahead/Typeahead.tsx @@ -3,7 +3,9 @@ import type { InputHTMLAttributes } from 'react'; import { useId } from 'react'; import { Fragment, useState } from 'react'; import { Combobox, Transition } from '@headlessui/react'; -import { ChevronDownIcon } from '@heroicons/react/20/solid'; +import { CheckIcon, ChevronDownIcon } from '@heroicons/react/20/solid'; + +import { Spinner } from '..'; export type TypeaheadOption = Readonly<{ // String value to uniquely identify the option. @@ -27,6 +29,7 @@ type Attributes = Pick< type Props = Readonly<{ errorMessage?: React.ReactNode; isLabelHidden?: boolean; + isLoading?: boolean; label: string; // Minimum query length before any results will be shown. minQueryLength?: number; @@ -81,6 +84,7 @@ export default function Typeahead({ disabled = false, errorMessage, isLabelHidden, + isLoading = false, label, minQueryLength = 0, noResultsMessage = 'No results', @@ -163,14 +167,20 @@ export default function Typeahead({ }} {...props} /> - - + {isLoading ? ( +
+ +
+ ) : ( + + + )} - {query.length >= minQueryLength && ( + {query.length >= minQueryLength && !isLoading && ( setQuery('')} as={Fragment} @@ -198,13 +208,26 @@ export default function Typeahead({ } value={option}> {({ selected }) => ( - - {option.label} - + <> + + {option.label} + + {selected && ( + + + )} + )} ))