Date Picker

Date Picker

DatePickers combine a DateInput and a Calendar to allow users to enter or select a date and time value.

For better customization we only expose the useDatePicker hook to let use have a free way to use your own styles

API Reference

TimeInput Props

PropertyTypeDescriptionDefault
labelReactNodeThe content to display as the label.-
valueDateValueThe current value of the date input (controlled).-
defaultValueDateValueThe default value of the date input (uncontrolled).-
placeholderValueDateValueA placeholder time that influences the format of the placeholder shown when no value is selected. Defaults current date at midnight.-
minValueDateValueThe minimum allowed date that a user may select.-
maxValueDateValueThe maximum allowed date that a user may select.-
localestringThe locale to display and edit the value according to.-
errorMessageReactNode | (v: ValidationResult) => ReactNodeAn error message for the date input.-
startContentReactNodeElement to be rendered in the left side of the date input.-
endContentReactNodeElement to be rendered in the right side of the date input.-
isRequiredbooleanWhether user input is required on the input before form submission.false
isReadOnlybooleanWhether the input can be selected but not changed by the user.-
isDisabledbooleanWhether the input is disabled.false
isInvalidbooleanWhether the input value is invalid.false
createCalendar(name: string) => CalendarA function that creates a Calendar object for a given calendar identifier.-
isDateUnavailable(date: DateValue) => booleanCallback that is called for each date of the calendar. If it returns true, then the date is unavailable.-
autoFocusbooleanWhether the element should receive focus on render.false
hourCycle12 | 24Whether to display the time in 12 or 24 hour format. This is determined by the user's locale.-
granularityhour | minute | secondDetermines the smallest unit that is displayed in the date picker. Typically "day" for dates.-
hideTimeZonebooleanWhether to hide the time zone abbreviation.false
shouldForceLeadingZerosbooleanWhether to always show leading zeros in the month, day, and hour fields.true
openbooleanOpen the calendar picker.-
defaultOpenbooleanOpen the calendar picker for default - (uncountrolled).-
onOpenChange(open: boolean) => void;Trigger when open state Change-
dateInputPropsDateInputPropsProps to be passed to the time DateInput component.-
calendarPropsCalendarPropsProps to be passed to the time Calendar component.-
timeInputPropsTimeInputPropsProps to be passed to the time TimeInput component.-

Usage

To use the DatePicker component, import useDatePicker from the library and use it like below.

import React from 'react';
import { useDatePicker, type UseDatePickerProps } from 'react-calendar-kit';
 
import CalendarButton from './calendar-button';
import { CK } from './calendar-primitives';
 
const DatePicker = (props: UseDatePickerProps) => {
  const { ref, state, getCalendarProps, getDateInputProps, getDialogProps, getTriggerProps } = useDatePicker(props);
 
  return (
    <div>
      <CK.DateInput {...getDateInputProps} ref={ref} endContent={<CalendarButton {...getTriggerProps} />} />
      {state.isOpen ? (
        <div {...getDialogProps}>
          <CK.Calendar {...getCalendarProps} visibleMonths={1} weekdayStyle="short" withPicker />
        </div>
      ) : null}
    </div>
  );
};
 
export default DatePicker;