Skip to main content

Common Examples

import { DateFieldYearlessRange } from "@servicetitan/anvil2";

function ExampleComponent() {
  return <DateFieldYearlessRange label="Date Range" />;
}

Controlled vs Uncontrolled

The DateFieldYearlessRange component can be used in controlled or uncontrolled mode.

Uncontrolled

Use defaultValue to set an initial value without controlling the state.

Controlled

Use value and onChange for full control over the component state.

Date Format Modes

The component supports two date format modes: mm/dd (default) and dd/mm.

With Validation

Show error states when validation fails.

Sizes

The component supports small, medium, and large sizes.

Custom Labels

Customize the accessible labels for the start and end date fields.

React Accessibility

  • The component uses a fieldset with a legend for proper grouping
  • Start and end date fields have individual accessible labels (visually hidden)
  • Error messages are announced via aria-live
  • The moreInfo tooltip content is also available to screen readers
For more guidance on form field labels and context, see input field context association best practices.

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 kept as a screen-reader-only <legend> element so the group remains accessible — any inline markdown is stripped to plain text.
Last modified on April 14, 2026