DatePicker
Choose a date from a calendar.
Examples
Values are Date objects in local time. onChange also supplies the formatted string for the current picker mode; named fields submit this string. Arrow keys move days, Home / End move within a week, and PageUp / PageDown move months. Use DateTimePicker for time, or DateRangePicker for a range.
import { DatePicker, Form, FormField } from '@ifhover/leaf-ui';
export function DatePickerBasic() {
return (
<Form layout="vertical">
<FormField label="Choose a date">
<DatePicker aria-label="Choose a date" placeholder="Pick a good day" />
</FormField>
<FormField label="Default date">
<DatePicker aria-label="Default date" defaultValue={new Date(2026, 9, 15)} />
</FormField>
<FormField label="Disabled date">
<DatePicker aria-label="Disabled date" defaultValue={new Date(2026, 9, 15)} disabled />
</FormField>
</Form>
);
}
import { DatePicker, Form, FormField, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';
export function DatePickerControlled() {
const [date, setDate] = useState<Date | null>(new Date(2026, 9, 15));
const [dateString, setDateString] = useState('2026-10-15');
return (
<Form layout="vertical">
<FormField label="Date in October">
<DatePicker
aria-label="Date in October"
value={date}
minDate={new Date(2026, 9, 5)}
maxDate={new Date(2026, 9, 25)}
onChange={(next, text) => {
setDate(next);
setDateString(text);
}}
/>
</FormField>
<Text tone="muted">October 5–25 are available. Current:{dateString || 'Not selected'}</Text>
<FormField label="Required date · Error">
<DatePicker
aria-label="Required date"
status="error"
required
placeholder="Set a deadline"
/>
</FormField>
</Form>
);
}
Date shortcuts
Customize Today with todayText, add shortcuts with renderExtraFooter, or hide Today with showToday=false.
import { Button, DatePicker, Flex, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';
export function DatePickerFooter() {
const [value, setValue] = useState<Date | null>(null);
const tomorrow = () => {
const next = new Date();
next.setDate(next.getDate() + 1);
next.setHours(0, 0, 0, 0);
setValue(next);
};
return (
<Flex direction="column" gap="sm" align="start">
<Text>Custom date shortcuts</Text>
<DatePicker
aria-label="Custom date shortcuts"
value={value}
onChange={setValue}
todayText="Today"
renderExtraFooter={
<Button variant="ghost" size="sm" onClick={tomorrow}>
Tomorrow
</Button>
}
/>
</Flex>
);
}
Extended features
import { DatePicker, Space } from '@ifhover/leaf-ui';
export function ExtensionDemo() {
return (
<Space wrap>
{(['year', 'quarter', 'month', 'week'] as const).map((picker) => (
<label key={picker} htmlFor={`period-${picker}`}>
{{ year: 'Year', quarter: 'Quarter', month: 'Month', week: 'Week' }[picker]}
<DatePicker id={`period-${picker}`} picker={picker} />
</label>
))}
</Space>
);
}
Custom display and weekday restrictions import { DatePicker, Flex, Space, Text } from '@ifhover/leaf-ui';
export function Capabilities() {
return (
<Space direction="vertical" align="stretch">
<Flex direction="column" gap="sm" align="center">
<Text>
{'Custom display and weekday restrictions'}
</Text>
<DatePicker
format="DD/MM/YYYY"
disabledDate={(date) => date.getDay() === 0 || date.getDay() === 6}
presets={[{ label: 'Today', value: () => new Date() }]}
/>
</Flex>
<Flex direction="column" gap="sm" align="center">
<Text>{'Select up to three dates'}</Text>
<DatePicker multiple maxCount={3} format="MM/DD" />
</Flex>
</Space>
);
}
Serialization and dates
format changes display text and the string argument of onChange; FormData keeps the canonical period/date representation described below. Square brackets escape literal text, such as YYYY-[Q]Q. Provide parse with a function-valued formatter. Dates are local calendar values; convert business timezones explicitly at the application boundary. Configure the first weekday with ConfigProvider's weekStartsOn.
DatePicker API
Types
Import DatePickerProps to describe component props. Option types in the API table link to their detailed fields above.
import type { DatePickerProps } from '@ifhover/leaf-ui';
Use name to include values in FormData. Uncontrolled fields follow form reset; reset controlled values in application state. Place controls in FormField for labels, help and errors. ConfigProvider supplies regional themes and translated built-in UI. Application labels and options are your responsibility.
Type YYYY-MM-DD and press Enter or move focus away to submit. Invalid dates and values outside minDate/maxDate are rejected. Click the month or year heading to switch panels. Today selects the current date. Use showToday, todayText and renderExtraFooter to customize shortcuts.
Clicking the field keeps typing focus; ArrowDown moves into the calendar, and Escape discards pending text. Other input attributes and aria-* target the input; className/style target the wrapper.
Picker formats: date → YYYY-MM-DD, year → YYYY, quarter → YYYY-QN, month → YYYY-MM, week → YYYY-Www. These formats apply to display, manual input, the onChange string and FormData.
SingleDatePicker API
MultipleDatePicker API
DatePreset