FormikSelect
Basic Usage
import { FormikSelect } from '@krakentech/coral-formik';
import { Button } from '@krakentech/coral';
import { Formik, Form } from 'formik';
<Formik
initialValues={{ select: null }}
onSubmit={() => console.log('Submitted')}
validationSchema={yup.object().shape({
select: yup.object().nullable().required('This field is required'),
})}
>
<Form method="post">
<FormikSelect
name="select"
label="Select Greek Letter"
values={[
{ label: 'Alpha', value: 'Alpha' },
{ label: 'Alpha', value: 'Alpha' },
{ label: 'Beta', value: 'Beta' },
...
]}
/>
<Button type="submit">Submit</Button>
</Form>
</Formik>Full API
| Name | Type | Default |
|---|---|---|
defaultOpen | booleanIf | false |
disabled | booleanIf | false |
label | stringThe accessible label for the select. | Label |
id | stringThe HTML ID passed to both the label, and the select. | |
name | stringThe field name used on the POST request when the form is submitted. | |
onBlur | FocusEventHandler<HTMLButtonElement>Callback fired when the select loses user focus. | |
onChange | (value?: SelectOption | null | undefined) => voidCallback fired each time the user selects an option.
| |
onClose | () => voidCallback fired when the select is closed. | |
onOpen | () => voidCallback fired when the select is opened. | |
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 |
values | SelectOption[]The options to be displayed in the select dropdown. | [] |
theme | ResponsiveVariant<"base100" | "secondary500">The colourway applied to this component. | base100 |
attributes | AttributesThis prop can be used to pass HTML attributes directly to the component.
We currently allow passing Example usage: | |
validate | FieldValidator | undefinedAn optional field level validation function. See Formik docs for more details |