Calendar
Month-view calendar. Reuses the DatePicker core month-grid algorithm (leading / trailing padding and today detection), with single / range / multiple selection, an optional date-range constraint, and arrow-key grid navigation.
Basic usage
The first group is single selection (default, controlled); the second uses selection="range" — two clicks set the span — with panels={2} showing two month panels side by side; the third uses selection="multiple" where clicks toggle dates (sorted by time); the fourth constrains selectable dates to the 10th–20th of the current month via range, with out-of-range days natively disabled; the fifth uses mode="input" to fold the always-visible panel into an input that expands on click and collapses after selecting (closeOnSelect={false} keeps it open).
import { useState } from 'react'
import { LhCalendar } from '@lh-ui/react'
export default function Demo() {
const [date, setDate] = useState(new Date())
return <LhCalendar value={date} onChange={setDate} />
}
Calendar Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| value | Current selection (controlled; a Date for single mode, a Date[] for range / multiple) | Date | Date[] | — | — |
| defaultValue | Default selection (uncontrolled) | Date | Date[] | — | — |
| selection | Selection mode | string | single / range / multiple | single |
| range | Optional date-range constraint | [Date, Date] | — | — |
| mode | Display mode: always-visible panel / input with an expanding panel | string | panel / input | panel |
| panels | Number of month panels shown at once (flex-wrapped) | number | — | 1 |
| placeholder | Placeholder text in input mode | string | — | — |
| closeOnSelect | Whether the panel collapses after selecting in input mode | boolean | — | true |
| sx | Shorthand layout props | SxProps | — | — |
Calendar events
| Event | Description | Callback signature | Vue equivalent |
|---|---|---|---|
| onChange | Selection changed (fires on both clicks and keyboard navigation) | (value: Date | Date[]) => void | @update:modelValue / @change |
| onSelect | A date was selected | (date: Date) => void | @select |
Passing value makes the component controlled (the selection is fully driven externally); omitting it (or passing defaultValue) uses the internal uncontrolled state. onChange fires in both modes, and the callback shape follows selection: a Date for single mode, a Date[] for range / multiple.
plus's #header / #cell scoped slots map to the renderHeader({ year, month }) and renderCell(date) render functions here; without them the default title and day number are rendered.
Keyboard interaction
Once the grid has focus: arrow keys move the date focus (left / right ±1 day, up / down ±7 days), Home / End jump to the row start / end, and PageUp / PageDown switch months; the focused date is selected immediately (out-of-range targets are clamped back into the selectable range, and stay unselected if still disabled).
Accessibility
- Grid semantics
role="grid"(rowsrow, cellsgridcell); today emitsaria-current="date", selected cells emitaria-selected, andaria-labelisyyyy-MM-dd - Roving tabindex: the focused date has
tabindex=0, all other dates-1 - Out-of-range dates are natively
disabledand removed from interaction - The input in input mode is
role="combobox"witharia-expandedandaria-haspopup="grid"
ref
forwardRef<HTMLDivElement> — the root element (the panel container in panel mode; the input plus expanded panel in input mode).
Styles
import '@lh-ui/react/theme.css'
import '@lh-ui/react/style/calendar'