DatePicker

free

DatePicker provides compact calendar-backed date entry for forms and filters.

import DatePicker from '@/components/ui/date-picker';

export default function BasicDemo() {
  return <DatePicker placeholder="Pick a date" />;

Installation

Add this component with the NateUI CLI.

npx nateui@latest add DatePicker

Examples

Basic

import DatePicker from '@/components/ui/date-picker';

export default function BasicExampleDemo() {
  return <DatePicker placeholder="Pick a date" />;

Range picker

import DatePicker from '@/components/ui/date-picker';

const DatePickerRange = DatePicker.Range;

Date time picker

import DatePicker from '@/components/ui/date-picker';

const DateTimepicker = DatePicker.DateTime;

Controlled

import { useState } from 'react';
import DatePicker from '@/components/ui/date-picker';

const DatePickerRange = DatePicker.Range;

Format

Input format:
Inner label format:
import DatePicker from '@/components/ui/date-picker';

export default function FormatDemo() {
  const date = new Date();

Custom Render

import DatePicker from '@/components/ui/date-picker';
import Badge from '@/components/ui/badge';

export default function CustomRenderDemo() {

Disable out of period date

import dayjs from 'dayjs';
import DatePicker from '@/components/ui/date-picker';

export default function DisableOutOfPeriodDateDemo() {

Disabled certain date

import { useState } from 'react';
import DatePicker from '@/components/ui/date-picker';

export default function DisabledCertainDateDemo() {

Multiple date view

import DatePicker from '@/components/ui/date-picker';

const DatePickerRange = DatePicker.Range;

Disabled Input

import { useState } from 'react';
import DatePicker from '@/components/ui/date-picker';

export default function DisabledInputDemo() {

Inputtable

import DatePicker from '@/components/ui/date-picker';

export default function InputtableDemo() {
  return (

Input Size

import DatePicker from '@/components/ui/date-picker';

export default function InputSizeDemo() {
  const date = new Date();

Input Affix

Prefix:
Suffix:
import DatePicker from '@/components/ui/date-picker';
import { PiCalendar, PiCalendarBlank } from 'react-icons/pi'

export default function InputAffixDemo() {

Clear Button

No clear button:
Custom clear button:
import DatePicker from '@/components/ui/date-picker';
import Button from '@/components/ui/button';

export default function ClearButtonDemo() {

Localization

import DatePicker from '@/components/ui/date-picker';
import 'dayjs/locale/ko';

export default function LocalizationDemo() {

API

DatePicker exports a root picker plus DatePicker.Range and DatePicker.DateTime.

Shared Picker Props

These props are available on DatePicker, DatePicker.Range, and DatePicker.DateTime.

PropDescriptionTypeDefault
clearableWhether the value can be cleared from the input.booleantrue
clearButtonCustom clear control rendered in the input suffix.ReactNode-
disabledDisable the input and prevent opening the picker.booleanfalse
inputPrefixContent rendered before the input text.ReactNode-
inputSuffixContent rendered after the input text when no clear button is shown.ReactNodeCalendar icon
inputtableAllow typing into the input.booleanfalse
nameName passed to the underlying input.stringComponent-specific
onBlurCalled when the input loses focus.PickerFocusHandler-
onDropdownCloseCalled after the floating calendar closes.() => void-
onDropdownOpenCalled after the floating calendar opens.() => void-
onFocusCalled when the input receives focus.PickerFocusHandler-
placeholderPlaceholder shown when no value is selected.string-
sizeControl size for the input.ControlSize'md'
typeNative input type forwarded to the input.HTMLInputTypeAttribute'text'

Shared Calendar Props

These props are forwarded from the picker to the calendar grid.

PropDescriptionTypeDefault
dateViewCountAmount of date views displayed in the picker.number1
dayClassNameApply class names to days based on the date and modifiers.DatePickerDayClassName-
dayStyleApply inline styles to days based on the date and modifiers.DatePickerDayStyle-
defaultMonthDefault month for the uncontrolled picker view.DateSelected value or new Date()
defaultViewDefault picker view.PickerView'date'
disableDateSpecify dates that cannot be selected.DatePickerDisableDate-
disableOutOfMonthDisable days outside the visible month.booleanfalse
enableHeaderLabelEnable the header label to trigger view changes.booleantrue
firstDayOfWeekFirst day of the week.FirstDayOfWeek'monday'
hideOutOfMonthDatesHide days outside the visible month.booleanfalse
hideWeekdaysHide the weekday row.booleanfalse
labelFormatMonth and year format used by the date view header.DatePickerLabelFormat{ month: 'MMM', year: 'YYYY' }
localeDayjs locale used by the picker.stringConfig locale
lockViewKeep the current view level after selecting a month or year.booleanfalse
maxDateMaximum selectable date.Date-
minDateMinimum selectable date.Date-
renderDayRender custom day content.DatePickerRenderDay-
weekdayLabelFormatWeekday display format.string'dd'
weekendDaysWeekday indexes treated as weekends.DatePickerWeekendDays[0, 6]
yearLabelFormatYear label format.string'YYYY'

DatePicker

PropDescriptionTypeDefault
classNameClass names applied to the picker input.string-
closePickerOnChangeWhether to close the picker after a date is selected.booleantrue
defaultOpenWhether the picker is open on first render.booleanfalse
defaultValueDefault value of DatePicker. Use value for controlled usage.Date | null-
inputFormatDatePicker input display format.string'YYYY-MM-DD'
inputtableBlurCloseWhether to close the picker on input blur when inputtable is enabled.booleanfalse
openPickerOnClearWhether to open DatePicker after clearing the value.booleanfalse
onChangeCallback when a date cell is selected.DatePickerChangeHandler-
refRef forwarded to the underlying input.Ref<HTMLInputElement>-
valueControlled DatePicker value.Date | null-
...nativeDivPropsNative props for the wrapper, excluding onChange and value.NativeDatePickerDivProps-

DatePicker.Range

PropDescriptionTypeDefault
classNameClass names applied to the range picker input.string-
closePickerOnChangeWhether to close the picker after the range is selected.booleantrue
defaultOpenWhether the range picker is open on first render.booleanfalse
defaultValueDefault value of DatePicker.Range. Use value for controlled usage.DateRangeValue[null, null]
inputFormatDatePicker.Range input display format.string'YYYY-MM-DD'
openPickerOnClearCall the open callback after clearing. The range picker always reopens on clear.booleanfalse
onChangeCallback when the date range is selected.DateRangeChangeHandler-
refRef forwarded to the underlying input.Ref<HTMLInputElement>-
separatorSeparator between dates in the input.string'~'
singleDateAllow one date to be selected as both range endpoints.booleanfalse
valueControlled DatePicker.Range value.DateRangeValue-
...nativeDivPropsNative props for the wrapper, excluding owned picker props.NativeDateRangeDivProps-

DatePicker.DateTime

PropDescriptionTypeDefault
amPmWhether to set time input to 12-hour format.booleantrue
classNameClass names applied to the date-time picker input.string-
closePickerOnChangeWhether to close the picker after date or time selection.booleanfalse
defaultOpenWhether the date-time picker is open on first render.booleanfalse
defaultValueDefault value of DatePicker.DateTime. Use value for controlled usage.Date | null-
inputFormatDatePicker.DateTime input display format.string'DD-MMM-YYYY hh:mm a'
okButtonContentOK button content.ReactNode'OK'
openPickerOnClearWhether to open DatePicker.DateTime after clearing the value.booleanfalse
onChangeCallback when the date-time value changes.DatePickerChangeHandler-
refRef forwarded to the underlying input.Ref<HTMLInputElement>-
valueControlled DatePicker.DateTime value.Date | null-
...nativeDivPropsNative props for the wrapper, excluding owned picker props.NativeDateTimeDivProps-

Types

type ControlSize = 'lg' | 'md' | 'sm';
type PickerView = 'date' | 'month' | 'year';
type FirstDayOfWeek = 'sunday' | 'monday';
type DatePickerLabelFormat = { month: string; year: string };
type DatePickerWeekendDays = [number, number];
 
type DatePickerDayProps = {
  disabled: boolean;
  weekend: boolean;
  selectedInRange: boolean;
  selected: boolean;
  inRange: boolean;
  firstInRange: boolean;
  lastInRange: boolean;
  outOfMonth: boolean;
};
 
type DatePickerDayClassName = (
  date: Date,
  modifiers: DatePickerDayProps,
) => string;
type DatePickerDayStyle = (
  date: Date,
  modifiers: DatePickerDayProps,
) => CSSProperties;
type DatePickerDisableDate = (date: Date) => boolean;
type DatePickerRenderDay = (date: Date) => ReactNode;
type PickerFocusHandler = (
  event: FocusEvent<HTMLInputElement, Element>,
) => void;
 
type DatePickerChangeHandler = (value: Date | null) => void;
type DateRangeValue = [Date | null, Date | null];
type DateRangeChangeHandler = (value: DateRangeValue) => void;
 
type NativeDatePickerDivProps = Omit<
  ComponentProps<'div'>,
  'onChange' | 'value'
>;
type NativeDateRangeDivProps = Omit<
  ComponentProps<'div'>,
  'defaultValue' | 'onChange' | 'value'
>;
type NativeDateTimeDivProps = NativeDateRangeDivProps;