Skip to main content

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​

PropDescriptionTypeOptionsDefault
valueControlled valueDate | [Date, Date] | null——
defaultValueUncontrolled default valueDate | [Date, Date] | null—null
modePanel mode'date' | 'month' | 'year' | 'datetime' | 'range'—'date'
sizeSize'large' | 'medium' | 'small'—Follows ConfigProvider
disabledWhether to disableboolean—false
clearableWhether to be clearableboolean—true
placeholderPlaceholderstring—Derived from format and the locale pack
formatDisplay formatstring—'yyyy-MM-dd'
readonlyWhether the inner input is read-onlyboolean—true
rangeSeparatorSeparator for range valuesstring—'~'
cellClassNameCustom class for date cells(date: Date) => string——
popperClassExtra class for the panelstring——
sxShorthand layout propsSxProps——
Differences from lh-ui-plus
  • modelValue / update:modelValue are mapped to the value / defaultValue / onChange trio (React naming);
  • Panel positioning uses useLhPopper (geometry + viewport flip), while the Vue version hand-writes fixed positioning without flipping;
  • The datetime / range modes have no dedicated UI on the plus side either (ledger P-08); they currently behave like date. When an array range value is passed, confirming only closes the panel without overwriting it, so range data is never silently lost.

DatePicker events​

EventDescriptionCallback signatureVue equivalent
onChangeEmitted 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'