For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/v/0.6.0/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/v/0.6.0/en/components/date-range-picker.md.
  • English
  • DateRangePicker

    Select start and end dates or times to define a range.

    Controlled range

    basic.tsx
    import { type DateRange, DateRangePicker, Form, FormField, Text } from '@ifhover/leaf-ui';
    
    import { useState } from 'react';
    
    export function DateRangePickerBasic() {
      const [range, setRange] = useState<DateRange | null>(null);
      return (
        <Form layout="vertical">
          <FormField label="Date range">
            <DateRangePicker aria-label="Date range" value={range} onChange={setRange} />
          </FormField>
          {range && (
            <output>
              <Text tone="muted">
                {range[0].toLocaleDateString()} – {range[1].toLocaleDateString()}
              </Text>
            </output>
          )}
        </Form>
      );
    }
    

    Picker modes

    modes.tsx
    import { DateRangePicker, Form, FormField } from '@ifhover/leaf-ui';
    
    export function DateRangePickerModes() {
      return (
        <Form layout="vertical">
          <FormField label="Year range">
            <DateRangePicker aria-label="Year range" picker="year" placeholder="Year range" />
          </FormField>
          <FormField label="Month range">
            <DateRangePicker aria-label="Month range" picker="month" placeholder="Month range" />
          </FormField>
          <FormField label="Week range">
            <DateRangePicker aria-label="Week range" picker="week" placeholder="Week range" />
          </FormField>
          <FormField label="Date and time range">
            <DateRangePicker
              aria-label="Date and time range"
              picker="datetime"
              placeholder="Date and time range"
              use12Hours
            />
          </FormField>
        </Form>
      );
    }
    

    Quarters, presets and open endpoints

    Quarter range
    Allow an open end, or use a recent-seven-day preset
    capabilities.tsx
    import { DateRangePicker, Flex, Space, Text } from '@ifhover/leaf-ui';
    
    export function Capabilities() {
      return (
        <Space direction="vertical" align="stretch">
          <Flex direction="column" gap="sm" align="center">
            <Text>{'Quarter range'}</Text>
            <DateRangePicker picker="quarter" format="YYYY-[Q]Q" />
          </Flex>
          <Flex direction="column" gap="sm" align="center">
            {'Allow an open end, or use a recent-seven-day preset'}
            <DateRangePicker
              allowEmpty={[false, true]}
              disabledDate={(date) => date.getDay() === 0}
              presets={[
                {
                  label: 'Recent 7 days',
                  value: () => {
                    const end = new Date();
                    const start = new Date();
                    start.setDate(start.getDate() - 6);
                    return [start, end];
                  },
                },
              ]}
            />
          </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.

    DateRangePicker API

    PropertyTypeDefaultDescription
    popupPlacement'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end'—Placement relative to the trigger.
    popupClassNamestring—Custom class for the popup.
    popupStyleCSSProperties—Custom popup styles.
    popupRender(content: React.ReactNode) => React.ReactNode—Wrap or extend popup content; retain the supplied content to preserve interaction.
    getPopupContainer() => Element | DocumentFragment—Return a popup container, including a ShadowRoot.
    size'sm' | 'md' | 'lg''md'Control size
    status'error' | 'warning'—Validation appearance
    allowClearbooleantrueShow the clear button
    inputReadOnlyboolean—Disable typing while retaining panel selection.
    openboolean—Control whether the panel is open.
    defaultOpenboolean—Initial open state.
    picker'year' | 'quarter' | 'month' | 'week' | 'date' | 'datetime''date'Selection granularity
    minDateDate—Earliest / latest allowed values
    maxDateDate—Earliest / latest allowed values
    use12HoursbooleanfalseDisplay a 12-hour clock with AM/PM options
    showSecondsbooleantrueInclude seconds in date-time ranges; otherwise seconds are zero
    minuteStepnumber1Minute / second step, an integer from 1 to 60
    secondStepnumber1Minute / second step, an integer from 1 to 60
    onOpenChange(open: boolean) => void—Called when the panel opens or closes
    disabledDate(date: Date, position: 'start' | 'end') => boolean—Disable dates using business rules.
    disabledTime(parts: TimeParts, position: 'start' | 'end', date: Date) => boolean—Disable times; typing and panel selection use the same rules.
    formatstring | ((date: Date) => string)—Display format; dates support YYYY, MM, DD, HH, mm, ss and Q.
    parse(text: string) => Date | null—Parse entered text; return null on failure.
    presetsreadonly DatePreset<readonly [Date | null, Date | null]>[]—Presets; value may be computed on demand.
    onCalendarChange(range: readonly [Date | null, Date | null], info: { position: 'start' | 'end' }) => void—Changes during selection, including the current start/end position.
    panelValueDate—Controlled date displayed by the calendar panel.
    onPanelChange(date: Date) => void—Called when the displayed calendar period changes.
    cellRender(date: Date) => ReactNode—Customize calendar cell content.
    allowEmptyfalse | true | readonly [boolean, boolean]falseExplicitly allow open range endpoints.
    valuereadonly [Date, Date] | null | readonly [Date | null, Date | null] | nullnullControlled / initial range
    defaultValuereadonly [Date, Date] | null | readonly [Date | null, Date | null] | nullnullControlled / initial range
    onChange((value: readonly [Date, Date] | null, dateStrings: readonly [string, string]) => void) | ((value: readonly [Date | null, Date | null] | null, dateStrings: readonly [string, string]) => void)—Returns an ordered range and formatted strings; clearing returns null
    disabledbooleanfalseDisable interaction.
    requiredbooleanfalseRequire a non-empty value; compound controls validate once.
    namestring—Field name in native FormData.
    formstring—ID of the associated native form.
    refRef<HTMLInputElement>—Input element reference

    DateRange

    PropertyTypeDefaultDescription
    0DateRequiredStart, no later than the end
    1DateRequiredEnd

    Types

    Import types when defining reusable component props or assembling options.

    import type { DateRangePickerProps, DateRange } from '@ifhover/leaf-ui';

    Usage notes

    A DateRange is a readonly [Date, Date]. Years use January 1, months use the first day, and weeks default to Monday; configure weekStartsOn on ConfigProvider with ISO week numbers. Dates use local time.

    The two calendars navigate together. After choosing the start, hover a year, month, week or date to preview the range. Choosing the end commits immediately in every mode, without a footer confirmation. Reversed selections are sorted.

    For date-time ranges, use the top-right time button in each calendar to set that endpoint's time, then return to the calendar and choose dates. Set times before choosing the end date. Now sets the current time for that endpoint.

    With an existing complete range, changing either endpoint's time immediately updates the valid range without reselecting dates.

    Type endpoints separated by ~ and press Enter or move focus away. Formats are YYYY, YYYY-MM, YYYY-Www, YYYY-MM-DD and YYYY-MM-DD HH:mm:ss (omit seconds when showSeconds is false). Invalid or out-of-bounds input is not submitted. Escape discards unfinished input.

    FormData uses start/end with canonical formats. Uncontrolled fields follow form reset; reset controlled values in application state.