Date and time

Date Field

Enter a date segment by segment.

Rust
1use herogpui::components::date_picker::DateField;

Usage

Rust
1use herogpui::prelude::{Date, DateField};
2use gpui::prelude::*;
3use gpui::px;
4
5gpui::div()
6    .flex()
7    .flex_col()
8    .w(px(256.))
9    .gap(px(12.))
10    .children(vec![
11        DateField::new(self.date_input.clone())
12            // v3's Usage seeds the field with `defaultValue`.
13            .default_value(Date::new(2025, 12, 25))
14            .label("Start date")
15            .on_change(opt_date_cb(cx.listener(
16                |this, d: &Option<Date>, _, cx| {
17                    this.date_iso = *d;
18                    cx.notify();
19                },
20            )))
21            .into_any_element(),
22        para(
23            &match iso {
24                Some(d) => format!("Parsed: {}", d.format_iso()),
25                None => {
26                    "Type digits, or step a segment with the arrow keys".to_owned()
27                }
28            },
29            cx,
30        ),
31    ])

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

DateField

Date Field is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Date Field uses.

Styling

Date Field styling
StyleDescription
flex_col + gap(px(4.))Four-pixel field stack with label, group and message.
validity.first() branchInvalid state replaces help text with the first resolved error.
full_width(true)Full-width root and group.
FIELD_HEIGHT + field_radius + field tokensBase group geometry and primary field chrome; group text and slots use explicit 14px/20px metrics.
immediate hover/focus/invalid stylesReaches each state endpoint without interpolating field properties.
group px(12px) + gap(2px)Segment row uses 12px horizontal padding and a 2px GPUI gap rather than CSS's 1px gap.
px(2px) + radius_md + ConsolasSegment radius and padding match; Consolas supplies tabular figures, but text is not end-aligned independently.
focused_seg accent.softFocused segments use accent-soft; invalid segment foreground is only reflected by the group error chrome.
prefix/suffix + flex_shrink_0 + 4px inner marginsContent is inert and placeholder-colored, with equivalent spacing expressed inside the padded group.
FieldVariant::Secondary + colors.defaultSecondary field uses the neutral default palette without a shadow.
no stepper elementsDateField changes only through its segments and keyboard; the removed GPUI chevrons are covered headlessly.

API reference

Builders

Date Field builders
BuilderTypeDefaultDescription
content(render)AnyElement | Fn(values: DateFieldRenderProps) -> AnyElementBuilt-in field composition or a replacement content closure with complete field state.
full_width(bool)boolfalseExpands the root and input group to the available width.
new(state)stateThe bound InputState entity supplies stable internal identity rather than a caller element id.
value(Option<Date>, cx)Option<Date>, cxWrites a controlled Gregorian date through the bound state.
default_value(Date)DateSeeds an uncontrolled Gregorian date once.
on_change(callback)Fn(value: DateValue | null) -> ()Reports the date portion; time and zone value types are not surfaced.
placeholder_value(Date)DateSeeds empty-field keyboard edits with a Gregorian date.
is_required(bool)boolfalseMarks the field required and blocks empty native form submission.
is_invalid(bool)boolfalseForces invalid chrome and validation reporting.
min_value(Date)DateInclusive minimum Gregorian date.
max_value(Date)DateInclusive maximum Gregorian date.
is_date_unavailable(callback)Fn(date: DateValue) -> boolRejects individual Gregorian dates.
validate(callback)Fn(value: DateValue) -> ValidationError | true | nullCustom validation returns one optional GPUI message.
validation_behavior(ValidationBehavior)ValidationBehaviorValidationBehavior::NativeChooses blocking native or non-blocking ARIA-style form validation.
granularity(Granularity)GranularityGranularity::DayAdds time segments through the selected smallest unit.
hour_cycle(HourCycle)HourCycleHourCycle::LocaleDefaults to the system regional time format; an explicit cycle overrides it.
should_force_leading_zeros(bool)boollocaleForces two-digit month, day and hour segments; otherwise numeric padding follows the system regional date and time patterns.
is_disabled(bool)boolfalseDims the whole field, removes it from interaction and form data.
is_read_only(bool)boolfalseKeeps segment navigation and focus while blocking edits.
name(value) + form_field()value) + form_field(Registers a live ISO-formatted FormField.
auto_focus(bool)boolfalseFocuses the segmented input on first render.
variant(FieldVariant)FieldVariantFieldVariant::PrimarySelects shadowed field or lower-emphasis default surface chrome.
segment(render)DateSegmentHands custom content each supported Gregorian date or plain-time segment and its generated text. Date and time segments follow the operating system's regional order, separators, padding, and day-period names; era and time-zone segment kinds require value models does not expose.
prefix(element)AnyElementInert content before the segmented input.
suffix(element)AnyElementInert content after the segmented input.

Parts

Date Field parts
PartDescription
DateFieldField state, validation and form owner.
DateFieldOptional built-in label with required, invalid and disabled state.
DateFieldFocusable field chrome around input, prefix and suffix.
DateFieldBuilt-in segmented input using the operating system's regional date order and separators rather than an independently composable part.
DateFieldKeyboard-editable Gregorian date and optional plain-time segment with custom rendering and regional date order; era and time-zone kinds are unavailable with the current value model.
DateFieldInert leading content.
DateFieldInert trailing content.
DateFieldHelp text or generated format hint, hidden when invalid.
DateFieldResolved validation message; uses ErrorMessage as its built-in equivalent.

States

Date Field states
BuilderStateDescription
hover field backgroundHoveredInteractive group uses the field-hover fill outside focus.
focus_handle + ring_if_focusedFocus withinFocused segments ring the field and use focus chrome.
validation::resolve + invalid field chromeInvalidDanger field and segment styling replaces the description with an error.
is_disabled + disabled_opacityDisabledThe entire field is dimmed and inert.
is_read_only gates editsRead onlySegments remain navigable but cannot change.
is_required + FormFieldRequiredLabel marker and form validation reflect required state.
focused_seg + accent.softSegment focusedThe active segment uses accent-soft selection chrome.
DateFieldDisplay cleared/empty stateSegment placeholderIncomplete segments use muted placeholder text.