Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide
DocumentationFormikFormikDatePicker

FormikDatePicker

Basic Usage

import { FormikDatePicker } from '@krakentech/coral-formik'; import { Button } from '@krakentech/coral'; import { Formik, Form } from 'formik'; <Formik initialValues={{ datepicker: '' }} onSubmit={() => console.log('Submitted')} validationSchema={yup.object().shape({ datepicker: yup.string().required('This field is required'), })} > <Form method="post"> <FormikDatePicker name="datepicker" label="Select date" /> <Button type="submit">Submit</Button> </Form> </Formik>

Full API

NameTypeDefault
disabledboolean

If true, the component will be disabled and not respond to user interactions.

false
disableFutureboolean

If true, future dates will be disabled.

false
disablePastboolean

If true, past dates will be disabled.

false
defaultMonthDate

The default month to display when the DatePicker is opened.

endIconReactNode

The icon displayed at the end of the DatePicker input.

excludeDateIntervals{ start: Date; end: Date; }[]

A list of date intervals to exclude from selection. Each interval is defined by a start and end date.

[]
excludeDatesDate[]

A list of dates to exclude from selection.

[]
fullWidthResponsiveVariant<boolean>

If true, the input will take up the full width of its container.

idstring

The id of the input element. If unspecified, an id will be generated internally.

includeDateIntervals{ start: Date; end: Date; }[]

A list of date intervals to include from selection. Each interval is defined by a start and end date.

[]
includeDatesDate[]

A list of dates to include from selection.

[]
isClearableboolean

If true, the input will be clearable, allowing users to remove the selected date. This will render a clear button inside the input field.

false
labelstring

The label for the DatePicker input field.

localeSupportedLocale

The locale to use for formatting dates.

en-GB
maxDateDate | null

The maximum date allowed for selection.

minDateDate | null

The minimum date allowed for selection.

namestring

The field name used on the POST request when the form is submitted.

nextMonthButtonLabelstring

The aria-label for the DatePicker’s next month button.

'Next month'
nextYearButtonLabelstring

The aria-label for the DatePicker’s next year button.

'Next year'
numberOfMonthsnumber

The number of months to display in the DatePicker.

onBlurFocusEventHandler<HTMLInputElement>

Callback fired when the input loses user focus.

  • event The focus event source of the callback.
onCalendarClose() => void

Callback fired when the calendar popup is closed.

onCalendarOpen() => void

Callback fired when the calendar popup is opened.

onChange(date: Date | DateRange | null) => void

Callback fired when the selected date changes.

  • date The selected date or date range, depending on the selectsRange prop.
onClickOutside(event: Event | undefined) => void

Callback fired when the user clicks outside the DatePicker.

  • event The event source of the callback
onFocus(event: Event | undefined) => void

Callback fired when the DatePicker input gains user focus.

  • event The focus event source of the callback.
onInputClick() => void

Callback fired when the DatePicker input is clicked.

onKeyDown(event: KeyboardEvent<HTMLDivElement>) => void

Callback fired when a key is pressed down on the DatePicker input.

onMonthChange(date: Date) => void

Callback fired when the month is changed.

  • date The new month date.
onSelect(date: Date, event: Event | undefined) => void

Callback fired when a date is selected.

  • date The selected date.
  • event The event source of the callback.
openboolean

If true, the DatePicker will be opened by default when rendered.

themeResponsiveVariant<SharedThemeTypes>

The colourway applied to this component.

'base100'
placeholderTextstring

The placeholder text for the input field.

popperPlacementPlacement

Position of the popper relative to the input.

previousMonthButtonLabelstring

The aria-label for the DatePicker’s previous month button.

'Previous month'
previousYearButtonLabelstring

The aria-label for the DatePicker’s previous year button.

'Previous year'
optionalboolean

Add 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
selectsRangeboolean

If true, the DatePicker will allow selecting a range of dates.

false
shouldCloseOnSelectboolean

If true, the DatePicker will close the calendar popup when a date is selected.

true
showYearPickerboolean

If true, the DatePicker will show a year picker rather than a month picker.

false
showYearDropdownboolean

If true, the DatePicker will show a year dropdown for selecting years.

false
startIconReactNode

The icon displayed at the start of the DatePicker input field.

tabIndexnumber

The tab index for the DatePicker input.

titlestring

The label title for the DatePicker input.

yearDropdownItemNumbernumber

The number of items which are displayed in the year dropdown in each direction.

100
upLevelButtonLabelstring

The aria-label for the button that moves back to calendar view from Month or Year view.

'Back to Calendar'
monthSelectionLabelstring

The aria-label for the manual month selection.

'Select Month'
yearSelectionLabelstring

The aria-label for the manual year selection.

'Select Year'
datesTableLabelReactNode
monthsTableLabelReactNode
yearsTableLabelReactNode
validateFieldValidator | undefined

An optional field level validation function. See Formik docs  for more details

Last updated on