Skip to main content

Common Examples

Date string values

DateFieldRange accepts and returns date-only ISO 8601 strings (YYYY-MM-DD) for startDate and endDate. onChange returns that same date-only form, or null when an end is empty. A full ISO datetime is accepted and normalized to the calendar date in that string’s offset; the day in the string is kept. When you start from a JavaScript Date, build the string from the local year, month, and day. toISOString() is UTC, so it can name a different calendar date than the local one you mean to store.The field is one masked input, not two. The displayed value looks like mm/dd/yyyy - mm/dd/yyyy, with a space, hyphen, and space between the ends. A single digit followed by / is zero-padded (1/ becomes 01/). Typing does not swap an end date that is earlier than the start.

Default values

Pass defaultValue for an uncontrolled field. The field keeps later edits itself. Use null to start empty.

Controlled usage

Store a DateFieldRangeValue in state and pass it as value. onChange receives a DateFieldRangeChange, which adds validity flags the value prop does not accept. Copy startDate and endDate back into state. Pass null to clear both ends.

Constraint errors

The field reports validity and leaves the message to you. isInputValid is true only when both ends are complete dates. isDateRangeValid is a separate check on the last committed dates: an empty range passes unless required is set. An in-progress edit can leave isDateRangeValid true while isInputValid is false, because an incomplete end keeps the previous committed date. Show error only after isInputValid is true and the range is still not allowed. error also sets aria-invalid. A boolean true is the error style with no message.

Disabled hint text

The hint text can be disabled. If the hint text is disabled, ensure that the date format is displayed on the page.

Timezone

timezone sets the calendar’s Today action and, when the field has no value, the month it opens on. When the zone differs from the browser time zone, the calendar shows “Dates shown in” plus that zone’s abbreviation.

Disable calendar popover

The display of the Calendar can be prevented by passing disableCalendar.

Markdown in labels

The label prop supports inline markdown: bold (**text**), italic (*text*), bold and italic (***text***), highlight (==text==), and code (`text`).

Hide the label

Use hideLabel to visually hide the label. The label string is converted to an aria-label on the input so it remains accessible to screen readers — any inline markdown is stripped to plain text.

React Accessibility

The input is a textbox. With a string label, the visible label is associated with the input. hideLabel moves that string to aria-label and strips inline markdown. With no label, the input’s accessible name is “Select a date range”.required marks the input required and adds a visible asterisk plus screen-reader text on the label. error sets aria-invalid. Error text is announced with aria-live="assertive". Warning text uses aria-live="polite".Arrow Down opens the calendar and moves focus to the first control in the popover. Escape closes the calendar and returns focus to the input. Inside the calendar, arrow keys move by day or week, Page Up and Page Down move by month, and Shift plus those keys moves by year. Enter or Space selects the focused day. Selecting the end date closes the calendar and returns focus to the input.

Testing

The field’s interactive sub-elements carry a stable data-anv-part attribute so end-to-end tests can target them directly. The library owns the part names; you supply the instance identifier.Attach your own data-* attribute (such as data-cy or data-testid) to the field. It is forwarded to the masked text input — the one element present in every mode, including disableCalendar:
The masked input also exposes the current range for assertions:
The popover and calendar render in the browser’s top layer, outside the input’s subtree, so a descendant query scoped to your data-cy on the input will not reach them. Target them by their part attribute directly ([data-anv-part="date-calendar"]) or by the popover’s data-testid="calendar-popover". Only one calendar is open at a time.
Last modified on October 5, 2026