Skip to main content
Kobalte

Date Field

Since v2.0.0@kobalte/core/date-fieldSource

A date field allows users to enter and edit date values using a keyboard. Each part of a date value is displayed in an individually editable segment.

Import

import { DateField } from "@kobalte/core/date-field";
// or
import {
Root,
Label,
Input,
Segment,
Description,
ErrorMessage,
HiddenInput,
} from "@kobalte/core/date-field";

Features

  • Values are native JS Date objects — no external date library required.
  • Dates can optionally include a time, down to the minute or second, via the granularity prop.
  • Support for locale-specific formatting, number systems, hour cycles, and right-to-left layout.
  • Each date/time unit is displayed as an individually focusable and editable segment, which allows users an easy way to edit dates using the keyboard, in any format and locale.
  • Segments are editable using an easy to use numeric keypad, and all interactions are accessible using touch-based screen readers.
  • Can be controlled or uncontrolled.
  • Integrates with HTML forms via a hidden native input serialized as a local (non-UTC) ISO 8601-style string.

Anatomy

The date field consists of:

  • DateField: The root container for the date field.
  • DateField.Label: The label that gives the user information on the date field.
  • DateField.Input: The container for the segments.
  • DateField.Segment: The component that represents a unit of a date/time (year, month, day, hour, etc.).
  • DateField.Description: The description that gives the user more information on the date field.
  • DateField.ErrorMessage: The error message that gives the user information about how to fix a validation error on the date field.
  • DateField.HiddenInput: The native html input that is visually hidden in the date field, used for HTML form submission.
<DateField>
<DateField.Label />
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
<DateField.Description />
<DateField.ErrorMessage />
<DateField.HiddenInput />
</DateField>

Example

Event date
export function BasicExample() {
return (
<DateField class={style["date-field"]}>
<DateField.Label class={style["date-field__label"]}>
Event date
</DateField.Label>
<DateField.Input class={style["date-field__field"]}>
{(segment) => (
<DateField.Segment
class={style["date-field__segment"]}
segment={segment()}
/>
)}
</DateField.Input>
</DateField>
);
}
.date-field {
display: flex;
flex-direction: column;
gap: 4px;
}
.date-field__label {
color: hsl(240 6% 10%);
font-size: 14px;
font-weight: 500;
user-select: none;
}
.date-field__field {
display: flex;
padding: 4px 8px;
border-radius: 6px;
width: 150px;
white-space: nowrap;
forced-color-adjust: none;
background-color: #fff;
border: 1px solid hsl(240 6% 90%);
color: hsl(240 4% 16%);
font-size: 14px;
}
.date-field__field:focus-within {
outline: 2px solid hsl(200 98% 39%);
outline-offset: -1px;
}
.date-field__segment {
padding: 0 2px;
font-variant-numeric: tabular-nums;
text-align: end;
}
.date-field__segment[data-type="literal"] {
padding: 0;
}
.date-field__segment[data-placeholder] {
color: hsl(240 4% 46%);
font-style: italic;
}
.date-field__segment:focus {
color: #fff;
background: hsl(200 98% 39%);
outline: none;
border-radius: 4px;
}
.date-field__segment::selection {
background-color: transparent;
}
.date-field__description {
color: hsl(240 5% 26%);
font-size: 12px;
user-select: none;
}
.date-field__error-message {
color: hsl(0 72% 51%);
font-size: 12px;
user-select: none;
}
[data-theme*="dark"] .date-field__label {
color: hsl(240 5% 84%);
}
[data-theme*="dark"] .date-field__field {
background-color: hsl(240 4% 16%);
border: 1px solid hsl(240 5% 34%);
color: hsl(0 100% 100% / 0.9);
}
.date-field__field[data-invalid] {
border-color: hsl(0 72% 51%);
outline-color: hsl(0 72% 51%);
}
[data-theme*="dark"] .date-field__segment[data-placeholder] {
color: hsl(0 100% 100% / 0.5);
}
[data-theme*="dark"] .date-field__description {
color: hsl(240 5% 65%);
}

Usage

Default value

A DateField displays a placeholder by default. An initial, uncontrolled value can be provided to the DateField using the defaultValue prop.

Date values are native JS Date objects.

<DateField defaultValue={new Date(2024, 0, 15)}>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
</DateField>

Controlled value

The value prop can be used to make the value controlled. The onChange event is fired when the date value changes.

Selected date: 1/15/2024

import { createSignal, Show } from "solid-js";
function ControlledValueExample() {
const [value, setValue] = createSignal(new Date(2024, 0, 15));
return (
<>
<DateField value={value()} onChange={setValue}>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
</DateField>
<p>
Selected date:{" "}
<Show when={value()} fallback={"--"}>
{value().toLocaleDateString()}
</Show>
</p>
</>
);
}

Granularity

The granularity prop allows you to control the smallest unit that is displayed by a DateField. By default, dates are displayed with "day" granularity (no time). More granular values can be displayed by setting granularity to "hour", "minute", or "second".

<DateField granularity="second">
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
</DateField>

Minimum and maximum values

The minValue and maxValue props can be used to perform builtin validation. This marks the date field as invalid using ARIA if the user enters a date outside the allowed range.

<DateField
defaultValue={new Date(2024, 5, 15)}
minValue={new Date(2024, 0, 1)}
maxValue={new Date(2024, 11, 31)}
>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
<DateField.ErrorMessage>Select a date in 2024.</DateField.ErrorMessage>
</DateField>

Placeholder value

A placeholderValue can be provided to influence the format of the placeholder shown when no value is selected, and acts as the starting point for interactions.

<DateField placeholderValue={new Date(2030, 0, 1)}>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
</DateField>

Hour cycle

By default, DateField displays times in either 12 or 24-hour format depending on the user's locale. This can be overridden using the hourCycle prop.

<DateField granularity="minute" hourCycle={12}>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
</DateField>

Description

The DateField.Description component can be used to associate additional help text with a date field.

Date
Select a meeting date.
<DateField>
<DateField.Label>Date</DateField.Label>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
<DateField.Description>Select a meeting date.</DateField.Description>
</DateField>

Error message

The DateField.ErrorMessage component can be used to help the user fix a validation error. It should be combined with the validationState prop to semantically mark the date field as invalid for assistive technologies.

By default, it will render only when the validationState prop is set to invalid, use the forceMount prop to always render the error message (ex: for usage with animation libraries).

Date
import { createSignal } from "solid-js";
function ErrorMessageExample() {
const [value, setValue] = createSignal(undefined);
return (
<DateField
value={value()}
onChange={setValue}
validationState={value() === undefined ? "invalid" : "valid"}
>
<DateField.Label>Date</DateField.Label>
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
<DateField.ErrorMessage>Please select a date.</DateField.ErrorMessage>
</DateField>
);
}

HTML forms

Add a name prop to DateField and render DateField.HiddenInput to include the value in form submissions. The hidden input's value is the date serialized as a local ISO 8601-style string (YYYY-MM-DD, YYYY-MM-DDTHH:mm, or YYYY-MM-DDTHH:mm:ss, depending on granularity) — it deliberately omits a Z/UTC offset, since there's no explicit time zone to make that claim about.

<DateField name="date">
<DateField.Input>{segment => <DateField.Segment segment={segment()} />}</DateField.Input>
<DateField.HiddenInput />
</DateField>

API Reference

DateField

DateField is equivalent to the Root import from @kobalte/core/date-field.

PropDescription
valueDateValue (a native Date object)
The current value (controlled).
defaultValueDateValue
The default value (uncontrolled).
onChange(value: DateValue) => void
Handler that is called when the value changes.
placeholderValueDateValue
A placeholder date that influences the format of the placeholder shown when no value is selected. Defaults to today's date at midnight.
minValueDateValue
The minimum allowed date that a user may select.
maxValueDateValue
The maximum allowed date that a user may select.
hourCycle12 | 24
Whether to display the time in 12 or 24-hour format. By default, this is determined by the user's locale.
granularity'day' | 'hour' | 'minute' | 'second'
Determines the smallest unit that is displayed in the date field. Defaults to "day".
maxGranularity'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
Determines the largest unit that is displayed in the date field. Defaults to "year".
shouldForceLeadingZerosboolean
Whether to always show leading zeros in the day/month/hour fields. By default, this is determined by the user's locale.
idstring
A unique identifier for the component. Used to generate ids for nested components. Auto-generated if not provided.
namestring
The name of the date field. Submitted with its owning form as part of a name/value pair.
validationState'valid' | 'invalid'
Whether the date field should display its "valid" or "invalid" visual styling.
requiredboolean
Whether the date field is required.
disabledboolean
Whether the date field is disabled.
readOnlyboolean
Whether the date field is read only.
translationsDateFieldIntlTranslations
The localized strings of the component.
Data attributeDescription
data-validPresent when the date field is valid according to the validation rules.
data-invalidPresent when the date field is invalid according to the validation rules.
data-requiredPresent when the date field is required.
data-disabledPresent when the date field is disabled.
data-readonlyPresent when the date field is read only.

DateField.Label, DateField.Input, DateField.Segment, DateField.Description and DateField.ErrorMessage share the same data-attributes.

DateField.Segment

DateField.Segment represents an individually focusable and editable unit of the date/time value (year, month, day, hour, minute, second, day period, or a literal separator).

PropDescription
segmentDateSegment
A segment of the date field, obtained from the render-prop child of DateField.Input.
Data attributeDescription
data-separatorPresent when the segment is a literal separator.
data-typeThe segment's type (e.g. year, month, day, hour, dayPeriod, literal). Always present.
data-placeholderPresent when the segment's value is a placeholder.

DateField.ErrorMessage

PropDescription
forceMountboolean
Used to force mounting when more control is needed. Useful when controlling animation with SolidJS animation libraries.

Rendered elements

ComponentDefault rendered element
DateFielddiv
DateField.Labelspan
DateField.Inputdiv
DateField.Segmentdiv
DateField.Descriptiondiv
DateField.ErrorMessagediv
DateField.HiddenInputinput

Accessibility

Keyboard Interactions

KeyDescription
BackspaceDeletes the value in the current segment and moves focus to the previous segment when empty.
DeleteDeletes the value in the current segment and moves focus to the previous segment when empty.
ArrowRightMoves focus to the next segment.
ArrowLeftMoves focus to the previous segment.
ArrowUpIncrements the value of the current segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
ArrowDownDecrements the value of the current segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
PageUpIncrements the value of the current segment by a larger amount, rounding it to the nearest increment. The amount to increment by depends on the segment, for example 5 years, 2 months, 7 days, or 15 minutes. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
PageDownDecrements the value of the current segment by a larger amount, rounding it to the nearest decrement. The amount to decrement by depends on the segment, for example 5 years, 2 months, 7 days, or 15 minutes. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
HomeSets the current segment to its minimum value.
EndSets the current segment to its maximum value.
0-9Numeric segments (year, month, day, hour, minute, second) are typed directly. Focus automatically advances to the next segment once the segment is filled. The dayPeriod segment supports typeahead of its formatted name (e.g. "A" for AM).

Last updated: 11/28/26, 9:28 PM