Skip to content

DatePicker

DatePicker

The DatePicker component combines an input field with a calendar dropdown for date selection. It manages open/close state, date formatting, and auto-closes after selection.

Import

import { DatePicker } from '@thaparoyal/calendar-react';
import type { CalendarDate } from '@thaparoyal/calendar-react';
import '@thaparoyal/calendar-core/themes/themes.css';

Basic Usage

import { useState } from 'react';
import { DatePicker } from '@thaparoyal/calendar-react';
import type { CalendarDate } from '@thaparoyal/calendar-react';
import '@thaparoyal/calendar-core/themes/themes.css';
function MyDatePicker() {
const [date, setDate] = useState<CalendarDate | null>(null);
return (
<div data-theme="indigo">
<DatePicker.Root
config={{ calendarType: 'BS', locale: 'en' }}
value={date}
onValueChange={setDate}
>
<DatePicker.Input placeholder="Select date..." />
<DatePicker.Trigger />
<DatePicker.Content>
<DatePicker.Calendar />
</DatePicker.Content>
</DatePicker.Root>
<p>Selected: {date ? `${date.year}-${date.month}-${date.day}` : 'None'}</p>
</div>
);
}

With Clear Button

Add DatePicker.ClearButton to let users clear the selection:

<DatePicker.Root
config={{ calendarType: 'BS', locale: 'en' }}
value={date}
onValueChange={setDate}
>
<DatePicker.Input placeholder="Select date..." />
<DatePicker.ClearButton />
<DatePicker.Trigger />
<DatePicker.Content>
<DatePicker.Calendar />
</DatePicker.Content>
</DatePicker.Root>

Custom Format

Change the date display format in the input field:

<DatePicker.Root
config={{ calendarType: 'BS', locale: 'en' }}
format="YYYY/MM/DD"
value={date}
onValueChange={setDate}
>
...
</DatePicker.Root>

Supported format tokens: YYYY (year), MM (month), DD (day).

AD Calendar DatePicker

<DatePicker.Root
config={{ calendarType: 'AD', locale: 'en' }}
value={date}
onValueChange={setDate}
>
...
</DatePicker.Root>

Nepali Numerals

<DatePicker.Root
config={{ calendarType: 'BS', locale: 'ne' }}
value={date}
onValueChange={setDate}
>
...
</DatePicker.Root>

Disabled Dates

Prevent specific dates from being selected:

<DatePicker.Root
config={{ calendarType: 'BS', locale: 'en' }}
disabledDates={[
{ year: 2081, month: 10, day: 5, calendarType: 'BS' },
{ year: 2081, month: 10, day: 15, calendarType: 'BS' },
]}
value={date}
onValueChange={setDate}
>
...
</DatePicker.Root>

Min/Max Date Constraints

Restrict the selectable date range:

<DatePicker.Root
config={{
calendarType: 'BS',
locale: 'en',
minDate: { year: 2080, month: 1, day: 1, calendarType: 'BS' },
maxDate: { year: 2082, month: 12, day: 30, calendarType: 'BS' },
}}
value={date}
onValueChange={setDate}
>
...
</DatePicker.Root>

Themes

Wrap with data-theme to apply any of the built-in themes:

<div data-theme="ocean">
<DatePicker.Root>...</DatePicker.Root>
</div>

Props

PropTypeDefaultDescription
configPartial<CalendarConfig>Calendar configuration (type, locale, min/max, etc.)
valueCalendarDate | nullControlled selected date
defaultValueCalendarDateInitial date
onValueChange(date: CalendarDate | null) => voidSelection callback
disabledDatesCalendarDate[]Non-selectable dates
formatstring'YYYY-MM-DD'Date format string

Sub-components

ComponentDescription
DatePicker.RootRoot provider — manages open/close state and selection
DatePicker.InputText input showing the formatted date value
DatePicker.TriggerButton to toggle the calendar dropdown
DatePicker.ContentDropdown container (positioned below input)
DatePicker.CalendarCalendar grid rendered inside the dropdown
DatePicker.ClearButtonButton to clear the current selection

CSS Classes

ClassElement
.trc-date-pickerRoot container
.trc-date-picker-input-wrapperInput + buttons wrapper
.trc-date-picker-inputText input
.trc-date-picker-triggerOpen/close button
.trc-date-picker-clearClear button
.trc-date-picker-contentDropdown container
.trc-date-picker-calendarCalendar inside dropdown