Skip to main content
For development, import DateFieldSingle from @servicetitan/anvil2. For design, find it in the Anvil2 file.

Anatomy

Date Field Single consists of five primary elements that enable users to select a single date through text input or a calendar picker.
Anatomy of the Date Field Single component
  1. Label - Identifies the field and its purpose
  2. Input field - Text input for manual date entry with format mask
  3. Helper text (Optional) - Description, format hint or error message

Options

Date Field Single supports the following configurations to accommodate different use cases and regional preferences.

Date Format Modes

Date Field Single supports two date format modes to match regional conventions. The default format is mm/dd/yyyy for US audiences, while dd/mm/yyyy is available for international users.

Sizes

Three size options accommodate different layout densities and visual hierarchies.

Calendar Picker

The calendar picker can be disabled when manual text entry is preferred or when the calendar interface is not suitable for the use case.

Behavior

Date Field Single responds to user interaction with distinct visual states and validation feedback.

Visual States

The component displays different visual states to communicate field status and interactivity. Default state shows the field ready for input. Focus state highlights the active field. Error state displays validation messages when dates are invalid or required fields are empty. Disabled state prevents interaction while maintaining visual context.

Calendar Interaction

Clicking the input field opens a popover calendar. Users can navigate months and select dates directly from the calendar. The calendar closes automatically after selection, and the selected date populates the input field.

Validation

Date Field Single validates input in real time. The component checks for parseable dates, required field completion, date constraints (min/max dates), and unavailable dates or days of the week. Error messages appear below the field when validation fails.

Usage Guidelines

Alternatives

Date Field Single vs Date Field Yearless

Use Date Field Single when the year is essential to the date selection, such as appointment scheduling or deadline setting. Use Date Field Yearless when the year is irrelevant, such as recurring annual events or template dates.

How to Use

Labeling and Context

Provide clear, descriptive labels that communicate the purpose of the date selection. Labels should indicate what the date represents and why it’s needed. Use helper text or descriptions when additional context helps users understand constraints or requirements.
  • Write labels that clearly communicate the purpose of the date selection
  • Include format hints to guide users on expected input format
  • Set appropriate date constraints (min/max dates) to prevent invalid selections
  • Display validation errors immediately when they occur
  • Use the calendar picker to provide visual date selection when helpful

Anti-pattern: Ambiguous Context and Format

Avoid creating confusion by omitting format guidance or using Date Field Single for dates where year information is irrelevant.
  • Use Date Field Single for recurring annual events where year doesn’t matter
  • Omit format hints when the date format might be ambiguous to users
  • Hide validation errors until form submission
  • Use placeholder text to communicate date format instead of format hints
  • Create labels that don’t clearly indicate what date is being selected

Content

Content within Date Field Single should be clear, concise, and actionable.
  • Labels should clearly indicate what date is being selected
  • Error messages should explain why a date is invalid and how to fix it
  • Format hints should match the selected mode (mm/dd/yyyy or dd/mm/yyyy)
  • Descriptions should provide context without overwhelming the user

Keyboard Interaction

Users can navigate Date Field Single using standard keyboard controls.

Input Field

Calendar Picker

Accessibility

Date Field Single includes built-in accessibility features. The component supports full keyboard navigation and screen reader compatibility. Ensure labels are descriptive and error messages are clear for assistive technology users. For more guidance on form field labels and context, see input field context association best practices.

Code

Common Examples

Date string values

DateFieldSingle accepts and returns ISO 8601 date strings (for example, "2025-07-02") rather than JavaScript Date objects. Convert Date values from API clients or Anvil1 Date Picker before passing them to the component.

Default values

Default values can be included in DateFieldSingle to use the field in an uncontrolled mode.

Controlled usage

The DateFieldSingle can be controlled. This means you can maintain the state outside the component. Listen for new dates with onChange and supply a date into the value prop.

Validation

Understanding the object passed back in onChange is key to understanding how to validate this field.isDateValid will tell you if the last entered date is valid according to the props you’ve supplied (e.g. required, minDate, maxDate, and unavailable).isInputValid will tell you only if the underlying input is a parseable date — this does not consider whether the date is good according the other props.isInputEmpty will tell you if the underlying input has no digits entered.Typically, you will want to use these values together to determine the overall validity of the field. Though the simplest implementation may likely suffice to use only isDateValid.

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

The timezone prop controls the meaning of the “Today” button and which month-year the calendar initially displays. When the timezone differs from the user’s locale, a disambiguation message appears below the calendar.

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.

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 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 27, 2026