DatePicker
A date picker with date / month / year panel modes, controlled / uncontrolled usage, keyboard grid navigation, and clearing.
Basic usage
Controlled selection
Current value: (not selected)
import { useState } from 'react'
import { LhDatePicker } from '@lh-ui/react'
export default function Demo() {
const [value, setValue] = useState<Date | null>(null)
return (
<LhDatePicker
value={value}
onChange={(val) => setValue(val as Date | null)}
/>
)
}
DatePicker Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Controlled value | Date | [Date, Date] | null | — | — |
| defaultValue | Uncontrolled default value | Date | [Date, Date] | null | — | null |
| mode | Panel mode | 'date' | 'month' | 'year' | 'datetime' | 'range' | — | 'date' |
| size | Size | 'large' | 'medium' | 'small' | — | Follows ConfigProvider |
| disabled | Whether to disable | boolean | — | false |
| clearable | Whether to be clearable | boolean | — | true |
| placeholder | Placeholder | string | — | Derived from format and the locale pack |
| format | Display format | string | — | 'yyyy-MM-dd' |
| readonly | Whether the inner input is read-only | boolean | — | true |
| rangeSeparator | Separator for range values | string | — | '~' |
| cellClassName | Custom class for date cells | (date: Date) => string | — | — |
| popperClass | Extra class for the panel | string | — | — |
| sx | Shorthand layout props | SxProps | — | — |
Differences from lh-ui-plus
modelValue/update:modelValueare mapped to thevalue/defaultValue/onChangetrio (React naming);- Panel positioning uses
useLhPopper(geometry + viewport flip), while the Vue version hand-writes fixed positioning without flipping; - The
datetime/rangemodes have no dedicated UI on the plus side either (ledger P-08); they currently behave likedate. When an array range value is passed, confirming only closes the panel without overwriting it, so range data is never silently lost.
DatePicker events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Emitted when a value is confirmed or cleared | (value: Date | [Date, Date] | null) => void | @change |
Panel interaction
- Click the title to drill down: date → month → year; clicking the title in the year view goes back to the month view;
- The footer "Today" jumps to the current month and preselects today; "OK" commits the pending selection;
- Clicking a leading / trailing cell of an adjacent month jumps the panel to that month.
Keyboard interaction
Trigger: Enter / Space / arrow keys / Home / End open the panel, Escape closes it. Date grid: arrow keys move focus (horizontal overflow flips the month), PageUp / PageDown flip the month while keeping the column, Enter / Space select, Escape closes; the month / year grids move cyclically within the grid. The trigger is role="combobox", the panel is role="dialog", and the calendar is a role="grid" with roving tabindex.
ref
forwardRef<HTMLDivElement> — the trigger root element.
Styles
import '@lh-ui/react/style/date-picker'