FormikAutocomplete
Basic Usage
import { FormikAutocomplete } from '@krakentech/coral-formik';
import { Button } from '@krakentech/coral';
import { Formik, Form } from 'formik';
<Formik
initialValues={{ autocomplete: '' }}
onSubmit={() => console.log('Submitted')}
validationSchema={yup.object().shape({
autocomplete: yup.string().required('This field is required')
})}
>
<Form method="post">
<FormikAutocomplete
name="autocomplete"
label="Greek Letters"
options={[
{ value: 'alpha', label: 'Alpha' },
{ value: 'beta', label: 'Beta' },
{ value: 'gamma', label: 'Gamma' },
{ value: 'delta', label: 'Delta' },
...
]}
/>
<Button type="submit">Submit</Button>
</Form>
</Formik>Full API
| Name | Type | Default |
|---|---|---|
disabled | booleanIf | false |
dropdownButtonOpenText | stringThe accessible text to display to screenreaders, labelling the dropdown toggle button when the menu is closed. | Open |
dropdownButtonCloseText | stringThe accessible text to display to screenreaders, labelling the dropdown toggle button when the menu is open. | Close |
fullWidth | ResponsiveVariant<boolean>If | |
id | stringAn accessible ID for the input element. If not provided, one will be generated internally. | |
name | stringThe field name used on the POST request when the form is submitted. | |
noDataLabel | stringThe text to display when the user has entered a search term, but there are no matching options. | 'No options' |
onBlur | () => voidCallback fired whenever the input element loses user focus. | |
onChange | (label: string | null, value: string | null, reason: AutocompleteChangeReason) => voidCallback fired whenever the selected option changes.
| |
onClose | (reason: AutocompleteCloseReason) => voidCallback fired whenever the combobox menu is closed.
| |
onHighlightChange | (label: string | null, value: string | null, reason: AutocompleteHighlightChangeReason) => voidCallback fired whenever the highlighted menu option changes.
| |
onInputChange | (label: string | null, value: string | null, reason: AutocompleteInputChangeReason) => voidCallback fired whenever the input value changes.
| |
onItemClick | (label: string | null | undefined, value: string | null | undefined, reason: string) => voidCallback fired whenever a customer explicitly clicks on a dropdown item.
| |
onClear | () => voidCallback fired whenever the clear icon is clicked on the input. | |
onOpen | () => voidCallback fired whenever the combobox menu is opened. | |
options | AutocompleteOption[]The options to display in the Autocomplete dropdown.
Each option should have a | |
label | stringThe label to display inside the TextField. | |
optional | booleanAdd an optional flag to the label for this field (controlled by https://coral-oe.vercel.app/?path=/docs/guides-configurationβdocs#overrides-optional-indicatorΒ optionalIndicator). This should be set to true if you have set this field to be optional in your validation schema. | false |
theme | ResponsiveVariant<"secondary500" | "base100">The colourway applied to this component. | |
isLoading | booleanIf | |
loadingText | stringThe text to display when the Autocomplete is in a loading state. | |
filterOptions | (option?: string | undefined, inputValue?: string | undefined) => booleanA function that filters the options list based on the supplied option and input value. | |
validate | FieldValidator | undefinedAn optional field level validation function. See Formik docsΒ for more details |