Gecko UIGecko UI

DateRangeInput

Input component for selecting a date range with calendar popup

DateRangeInput

An input component for selecting date ranges. Features segmented date input fields, a floating calendar with dual-month display, and smart date validation.

Installation

import { DateRangeInput } from '@geckoui/geckoui';

Basic Usage

DD/MM/YYYY - DD/MM/YYYY
// - //
'use client';

import { useState } from 'react';
import { DateRangeInput } from '@geckoui/geckoui';
import type { DateRange } from '@geckoui/geckoui';

function Example() {
  const [value, setValue] = useState<DateRange | undefined>();

  return (
    <DateRangeInput value={value} onChange={(v) => setValue(v ?? undefined)} />
  );
}

Props API

PropTypeDefaultDescription
valueDateRange-Selected date range with from and to properties (ISO format: YYYY-MM-DD)
onChange(value: DateRange | null) => void-Callback when date range changes
format'DD/MM/YYYY' | 'MM/DD/YYYY' | 'YYYY/MM/DD''DD/MM/YYYY'Display format for date segments
separatorstring'/'Separator between date segments
rangeSeparatorstring' - 'Separator between from and to dates
numberOfMonths1 | 22Number of months to display in calendar
calendarPlacementPlacement'bottom-start'Calendar popup position (from @floating-ui/react)
floatingStrategy'absolute' | 'fixed''absolute'Floating UI positioning strategy
disabledbooleanfalseDisable the input
readOnlybooleanfalseMake the input read-only
hasErrorbooleanfalseShow error styling
hideCalendarbooleanfalseHide the calendar popup
hideCalendarIconbooleanfalseHide the calendar icon
hideClearIconbooleanfalseHide the clear button
placeholderstring-Custom placeholder text
placeholderClassNamestring-CSS class for placeholder
prefixFC | ReactNode-Element before the input
suffixFC | ReactNode-Element after the input
classNamestring-CSS class for input container
wrapperClassNamestring-CSS class for wrapper div
calendarClassNamestring-CSS class for calendar container
onSubmit() => void-Callback on Enter/Space key
onStateUpdate(state) => void-Callback when input segments change

DateRange Type

interface DateRange {
  from: string | null;  // ISO format: 'YYYY-MM-DD'
  to?: string | null;   // ISO format: 'YYYY-MM-DD'
}

Examples

With Default Value

Pre-populate the input with a date range:

DD/MM/YYYY - DD/MM/YYYY
// - //

Selected: 2024-06-01 - 2024-06-15

const [value, setValue] = useState<DateRange | undefined>({
  from: '2024-06-01',
  to: '2024-06-15',
});

<DateRangeInput value={value} onChange={(v) => setValue(v ?? undefined)} />

Date Formats

Choose between different date display formats:

DD/MM/YYYY (default)

DD/MM/YYYY - DD/MM/YYYY
// - //

MM/DD/YYYY

MM/DD/YYYY - MM/DD/YYYY
// - //

YYYY/MM/DD

YYYY/MM/DD - YYYY/MM/DD
// - //
<DateRangeInput format="DD/MM/YYYY" />  // 15/06/2024 - 30/06/2024
<DateRangeInput format="MM/DD/YYYY" />  // 06/15/2024 - 06/30/2024
<DateRangeInput format="YYYY/MM/DD" />  // 2024/06/15 - 2024/06/30

Number of Months

Display one or two months in the calendar:

Single month

DD/MM/YYYY - DD/MM/YYYY
// - //

Dual months (default)

DD/MM/YYYY - DD/MM/YYYY
// - //
<DateRangeInput numberOfMonths={1} />  // Single month view
<DateRangeInput numberOfMonths={2} />  // Dual month view (default)

Disabled and Read-only

Disabled

DD/MM/YYYY - DD/MM/YYYY
// - //

Read-only

DD/MM/YYYY - DD/MM/YYYY
// - //
<DateRangeInput value={value} disabled />
<DateRangeInput value={value} readOnly />

Error State

DD/MM/YYYY - DD/MM/YYYY
// - //

Please select a valid date range

<DateRangeInput value={value} onChange={setValue} hasError />

Styling

The component uses BEM-style class names:

  • GeckoUIDateRangeInputWrapper - Wrapper container
  • GeckoUIDateInput - Main input container
  • GeckoUIDateInput--disabled - Disabled state
  • GeckoUIDateInput--readOnly - Read-only state
  • GeckoUIDateInput--error - Error state
  • GeckoUIDateInput--focus - Focused state
  • GeckoUIDateInput--calendar-open - Calendar is open
  • GeckoUIDateInput__segment - Date segment input
  • GeckoUIDateInput__separator - Separator between segments (/)
  • GeckoUIDateRangeInput__range-separator - Separator between dates (-)
  • GeckoUIDateRangeInput__calendar - Calendar container
  • GeckoUIDateInput__calendar-icon - Calendar icon
  • GeckoUIDateInput__clear-button - Clear button
  • GeckoUIDateInput__prefix - Prefix container
  • GeckoUIDateInput__suffix - Suffix container

Accessibility

  • Segmented inputs for fine-grained keyboard control
  • Tab navigation between date segments
  • Arrow keys to move between segments
  • Enter/Space to open calendar and submit
  • Click outside to close calendar
  • Clear button for resetting selection