# ChronoField

Crate: `libero`
Import: `use libero::{chrono::{NaiveDate, NaiveDateTime, NaiveTime, TimeDelta}, components::{ChronoField, DateRange}};`
Feature: `date-field` (off by default, turns on `date-picker`, `button`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/form/date/chrono_field.rs>
Index: [index.md](index.md) lists every other page
Description: A text field for every date and time value, typed leniently, with the matching `ChronoPicker` in a dropdown.

A text field for every date and time value, with a [ChronoPicker](chrono_picker.md)
in a dropdown. The value's type picks what the dropdown shows: `NaiveDate` a
calendar, `NaiveTime` a clock, `NaiveDateTime` both, a `DateRange` of either
picks two, and `TimeDelta` is a duration. The types are `chrono`'s, re-exported
as `libero::chrono`.

## Usage

```rust
use dioxus::prelude::*;
use libero::{chrono::NaiveDate, components::{ChronoField, Icon}};

#[component]
fn Demo() -> Element {
    let mut date = use_signal(|| None::<NaiveDate>);

    rsx! {
        ChronoField {
            value: date() /* Option<NaiveDate> */,
            onchange: move |next| date.set(next),
            leading: rsx! { Icon { variant: "standard", svg: pictogram_icons_lucide::calendar::outlined } },
            label: "When",
        }
    }
}
```

## Duration

A `TimeDelta` field holds a span of time rather than a moment. It shows
`1 h 30 min`, with the units from `DateLocale`, and posts ISO 8601, `PT1H30M`.
Typing reads `1 h 30 min`, `1h30`, `1:30` or a bare number of minutes. A
fraction such as `1.5 h` or `1,5 h` is refused as unreadable, not rounded.

The dropdown has a column each for the hours, the minutes at `step` and, with
`with_seconds`, the seconds. The minutes and seconds wrap round without
carrying into the next column. The value runs from `min`, 0 by default, to
`max`, 99 h 59 min 59 s by default, and never past 999 h 59 min 59 s. The
hours column ends at `max`.

A duration has its own errors: `Must be at least 15 min` names the bound it
missed, and `Not a valid duration` is text it cannot read. A screen reader
hears each column's value with its unit, `2 hours`.

```rust
use dioxus::prelude::*;
use libero::{chrono::TimeDelta, components::ChronoField};

#[component]
fn Demo() -> Element {
    let mut length = use_signal(|| TimeDelta::try_minutes(90));

    rsx! {
        ChronoField {
            label: "Length",
            value: length(),
            onchange: move |next| length.set(next),
            max: TimeDelta::try_hours(12),
            step: 15,
            name: "length",
        }
    }
}
```

## Typing

Typed text is read on blur or Enter, and leniently. Any separator works, as do
one-digit days, month names as a unique prefix, and a missing year. Two-digit
years are not read. Only the order of day, month and year follows `format`.
Text the field cannot accept stays, and the error says why. The form always
gets ISO 8601.

On a phone the dropdown opens as a sheet at the foot of the screen. Under a
finger, a tap opens only the picker and the keyboard stays down; the text box
under the picker takes typing. Below `sm`, a range shows short, `14–16 Sep`,
until the field takes focus.

## Localization

The language of names, labels and errors comes from the provider's
`Localization`. The patterns, first weekday and 12- or 24-hour clock come from
its `Formats`, `Formats::AMERICAN` by default or `Formats::GERMAN`.

## The value's type

A typed value alone does not name the type. A handler that stores into a typed
signal does, or a turbofish such as `ChronoField::<NaiveTime> { .. }`. For one
value type there are `DateField`, `TimeField`, `DateTimeField`, `DateRangeField`
and `DateTimeRangeField`, with only the props that type uses and no turbofish.

## Props

### `ChronoField<V: DateValue>`

| Prop | Type | Default | Description |
|---|---|---|---|
| `size` | `Responsive<Size>` | `md` | Control height, font size and the dropdown's picker. Or one per breakpoint, `size: responsive(Size::Sm).md(Size::Lg)`; the open picker follows too. |
| `radius` | `Responsive<ThemeAwareValue>` | `sm` | Corner radius of the frame. Or any CSS, e.g. `radius: "0"`. Or one per breakpoint, `radius: responsive(Size::Sm).md(Size::Xl)`. |
| `value` | `Option<V>` | - | The value. `None` is the empty field. Its type picks the dropdown. Pair it with `onchange`. A `TimeDelta` shows as `1 h 30 min` in the `DateLocale`'s units and is typed so, or as `1h30`, `1:30` or minutes; a fraction such as `1.5 h` is refused, not rounded. Below `sm`, a range shows short, `14–16 Sep`, until the field takes focus. |
| `onchange` | `EventHandler<Option<V>>` | - | Called on every pick, and when typed text is committed on blur or Enter. Emptied text commits `None`. |
| `level` | `DateLevel` | `Day` | Types and picks a `NaiveDate` as a day, a month (its first day) or a year (its January 1), typed as `September 2026` or `2026`. Ignored for other values. |
| `format` | `String` | `(Formats::date)(level)` | How the text shows the value, in dayjs tokens. The default is `MMMM D, YYYY` in American formats, `D. MMMM YYYY` in German, and `MMMM YYYY` or `YYYY` in both for a month or a year. Typed text is read leniently on blur or Enter: any separator, one-digit days, a month name's unique prefix and a missing year, but no two-digit year. Only the order of day, month and year has to match. Text the field cannot accept stays, with the error saying why. Names, labels and errors come from the provider's `Localization`, the first weekday and the 12- or 24-hour clock from its `Formats`. |
| `time_format` | `String` | `Formats::time` | How the text shows a time. `h:mm A` in American formats, `HH:mm` in German. |
| `min` | `V::Bound` | - | The earliest value accepted. For a range, the earliest end. A duration's is 0 when unset. |
| `max` | `V::Bound` | - | The latest value accepted. For a range, the latest end. A duration's is 99 h 59 min 59 s when unset, and never past 999 h 59 min 59 s. |
| `exclude_date` | `Callback<NaiveDate, bool>` | - | Days that are not accepted, on top of `min` and `max`. Ignored for a time, a month and a year. |
| `today` | `NaiveDate` | - | The day marked as today, and the year used when typed text has none. Unset, the platform clock answers after mount. |
| `variant` | `TimePickerVariant` | `analog` | A digital clock, `HH:MM` with a column to turn per part, or a clock face, for values with a time. |
| `with_seconds` | `bool` | `false` | Seconds in the text and on the clock, or a duration's seconds column. |
| `step` | `u8` | `5` | The minute step: minutes between the offered minutes, on a clock or a duration's minutes column. |
| `hour_step` | `u8` | `1` | Hours between the clock's offered hours, counted from midnight. |
| `second_step` | `u8` | `1` | Seconds between the clock's offered seconds, with `with_seconds`. |
| `open_to` | `DateLevel` | `level` | The view a `NaiveDate` dropdown first shows, as `DateLevel::Year` to start from the years. A level below `level` shows `level`. |
| `presets` | `Vec<DatePreset<V>>` | - | Values offered as buttons beside the dropdown's calendar, above it on a phone. Pressing one commits it and closes like a picked day. For a day or a range of days. |
| `week_numbers` | `bool` | `false` | An ISO week number before each week of days in the dropdown. Not in the mini calendar. |
| `weekend_days` | `Vec<Weekday>` | `Saturday, Sunday` | The days marked `data-weekend` and tinted in the error colour. |
| `hide_weekdays` | `bool` | `false` | Hides the weekday names over the days. Screen readers still get them as column headers. |
| `hide_outside_days` | `bool` | `false` | Blanks instead of the neighbouring months' days. |
| `twelve_hour` | `bool` | - | A 12-hour clock with AM and PM. Defaults to whether the time format is one. |
| `calendar` | `CalendarVariant` | `full` | A month of days, or `mini`, one row of days with buttons that page it. For a day or a date-time. |
| `days` | `usize` | `7` | Days in the mini calendar's row. |
| `columns` | `usize` | `1, or 2 for a range above sm` | Months side by side; below `sm` only as many as fit, at least one. Unset, a range of days below `sm` shows its months in one scrolling column, with its ends on top and a Save button. |
| `close_on_change` | `bool` | `true` | Picking a day, or a range's second end, closes the dropdown. Below `sm`, a sheet that no pick closes has a Save button that closes it: a range's scrolling months, a time, a date-time, a duration, or any value with this off. With it on, the clock's last hand closes the sheet, by a tap or Enter; arrows only step it. |
| `hide_save` | `bool` | `false` | Hides the sheet's Save button. The sheet still closes on a swipe down, a tap outside, focus leaving it, Escape, Enter in its text box, or the pick that completes the value. |
| `hide_entry_input` | `bool` | `false` | Hides the text box under the picker on a touch screen. The field's own text keeps the keyboard down there, so the value is then only picked. |
| `name` | `FieldName<Option<V>>` | - | What the field posts as, the value in ISO 8601 whatever the text shows. A path also binds it to the surrounding `Form`'s value when it has no `onchange`. |
| `validate` | `Validators<Option<V>>` | - | Rules over the value, shown once the field loses focus or its form is submitted. |
| `placeholder` | `String` | - | Shown while the text is empty. |
| `leading` | `Element` | - | Inside the frame, before the text, such as a decorative icon. An `Icon` without `size` takes one from the field's `size`. |
| `trailing` | `Element` | - | Inside the frame, after the text, such as a decorative icon or a unit. Not read with the input. |
| `label` | `Caption` | - | The caption above the control, and the field's name. |
| `description` | `Caption` | - | Between the label and the control. What to enter. |
| `label_trailing` | `Caption` | - | Content in the label row, outside the `<label>`, at the row's end: a button cannot sit inside the label. Takes a string or an `Element`. |
| `description_position` | `DescriptionPosition` | `Above` | Where the description sits: `above` the control, or `below` it. `below` keeps the controls of side-by-side fields level when only some have a description; give the row `align: "flex-start"`. Unset, the theme's `field.description_position`. A checkbox, switch or radio draws its description under the label either way. |
| `helper` | `Caption` | - | Under the control. Formatting rules, or what the entry changes. |
| `status` | `FieldStatus` | `Valid` | Validation state, under the helper. Text the field cannot accept shows its own error instead, such as `DateLocale::invalid_date`, `invalid_duration` or the bound it missed. |
| `required` | `bool` | `false` | Sets `required` on the input and marks the label. Inside a `Form`, an empty one fails the submit. |
| `disabled` | `bool` | `false` | Disables typing and the dropdown, and dims the field. |
| `readonly` | `bool` | `false` | Focusable and posted with the form, but not editable. `disabled` drops the field from the tab order and the post instead. |
| `dropdown_parts` | `Parts<ChronoDropdownPart>` | - | Styles the portaled dropdown and the picker in it. |

`format` takes the dayjs tokens `YYYY M MM MMM MMMM D DD dd ddd dddd` and
`[literal]` text. Props that only some value types use are ignored by the rest,
with a warning in debug builds.

Like every component, it also takes the shared props `sx`, `class`, `style`,
`states`, `hidden_from`, `visible_from`, and any extra HTML attributes. The attributes land on the input.

## Style API

Style a part with the `parts` prop, or address it as `[data-slot='…']` in your
own CSS. The names are stable. [Style API in Styling](styling.md#style-api)
explains how parts work.

| Part | `data-slot` | Description |
|---|---|---|
| `FieldPart::Label` | `label` | The label above the control. |
| `FieldPart::Required` | `required` | The required asterisk, in the label. |
| `FieldPart::LabelRow` | `label-row` | The row holding the label and its `label_trailing`; drawn only with a trailing slot. |
| `FieldPart::LabelTrailing` | `label-trailing` | The `label_trailing` slot, at the end of the label row. |
| `FieldPart::Description` | `description` | The caption between the label and the control. |
| `FieldPart::Frame` | `frame` | The bordered box around the control. |
| `FieldPart::Leading` | `leading` | The slot before the control: an icon, a prefix. |
| `FieldPart::Control` | `control` | The element the label names. |
| `FieldPart::Trailing` | `trailing` | The slot after the control: a chevron, a toggle. |
| `FieldPart::Helper` | `helper` | The caption under the control. |
| `FieldPart::Status` | `status` | The validation message. |

### Dropdown

The dropdown is portaled out of the field, so its parts take the
`dropdown_parts` prop. They match from the dropdown box at any depth.

| Part | `data-slot` | Description |
|---|---|---|
| `ChronoDropdownPart::Panel` | `dropdown` | The dropdown box itself. |
| `ChronoDropdownPart::SheetHandle` | `sheet-handle` | Below `sm`: the swipe strip atop the sheet. |
| `ChronoDropdownPart::Header` | `header` | Calendar: the row over a month, a year or a decade, with paging buttons and title. |
| `ChronoDropdownPart::Nav` | `nav` | Calendar: a paging button, in the header or beside the mini calendar's row. |
| `ChronoDropdownPart::Title` | `title` | Calendar: the month, year or decade heading, a button that climbs a level. |
| `ChronoDropdownPart::Months` | `months` | Days: the months side by side, or the mini calendar's row. |
| `ChronoDropdownPart::Weekday` | `weekday` | Days: a weekday name over a month's columns. |
| `ChronoDropdownPart::Day` | `day` | Days: a day button. |
| `ChronoDropdownPart::Month` | `month` | Mini calendar: the month over a day's number. |
| `ChronoDropdownPart::Blank` | `blank` | Days, `columns` over 1: an empty cell instead of a neighbour's day. |
| `ChronoDropdownPart::Cells` | `cells` | Months and years: their grid. |
| `ChronoDropdownPart::Cell` | `cell` | Months and years: a month or a year button. |
| `ChronoDropdownPart::Strip` | `strip` | Mini calendar: the row of days between its paging buttons. |
| `ChronoDropdownPart::Columns` | `columns` | Digital clock, duration: the columns. |
| `ChronoDropdownPart::Spin` | `spin` | Digital clock, duration: one column, a spinbutton. |
| `ChronoDropdownPart::Value` | `value` | Digital clock, duration: a column's value. |
| `ChronoDropdownPart::Neighbour` | `neighbour` | Digital clock, duration: the faded values above and below a column's value. |
| `ChronoDropdownPart::Separator` | `separator` | Digital clock: the `:` between columns. |
| `ChronoDropdownPart::Unit` | `unit` | Duration: the unit after each column. |
| `ChronoDropdownPart::Readout` | `readout` | Analog clock: the digits over the face, buttons that pick the hand. Scrolling range calendar: the picked range's two ends above the months. |
| `ChronoDropdownPart::Face` | `face` | Analog clock: the face, a slider. |
| `ChronoDropdownPart::Mark` | `mark` | Analog clock: a number on the face. |
| `ChronoDropdownPart::Ticks` | `ticks` | Analog clock: the ring of ticks for steps finer than the marks. |
| `ChronoDropdownPart::Hand` | `hand` | Analog clock: the hand. |
| `ChronoDropdownPart::Pivot` | `pivot` | Analog clock: the dot the hand turns on. |
| `ChronoDropdownPart::Presets` | `presets` | Calendar with `presets`: the column of preset buttons, a row on a phone. |
| `ChronoDropdownPart::Preset` | `preset` | Calendar with `presets`: a preset button. |
| `ChronoDropdownPart::WeekNumber` | `week-number` | Days with `week_numbers`: a week's number, and the empty cell over them. |

## Accessibility

### Keyboard

| Key | Action |
|---|---|
| `Down` or `Alt+Down` | Opens the dropdown and moves focus into the picker, onto the picked day or the clock, where the [ChronoPicker](chrono_picker.md#accessibility) keys apply. |
| `Enter` | In the text: reads and commits it. Text it cannot read is refused, with the reason announced. |
| `Escape` | Closes the dropdown. From inside it, moves focus back to the text. |
| `Tab` or `Shift+Tab` | Past the dropdown's last stop: moves on as Tab from the text would. Before its first stop: back to the text. |

### Libero handles

- Focus alone does not open the dropdown, so tabbing through the form changes
  nothing. A click opens it and stays in the text, so you can type at once.
- A pick that closes the dropdown moves focus back to the text.
- Focus leaving both the text and the dropdown closes it.
- A mouse click in the dropdown leaves focus in the text.
- Android's Back button closes the dropdown rather than the app. Focus in the
  dropdown goes back to the text.
- On a phone the dropdown opens as a sheet at the foot of the screen. A tap
  opens only the picker and the keyboard stays down; the text box under the
  picker takes typing.
- A duration's columns read each value with its unit, such as "2 hours".

### Example

A delivery date, `ChronoField { label: "Delivery date", .. }`: type the date at
once, click to open the calendar with the caret staying in the text, or press
Down to open it and pick a day with the arrows.

## Theme defaults

`theme.chrono_field` is a `ChronoFieldDefaults` with `size`, `radius` and
`close_on_change`. Names, labels and errors come from `Localization::date`, a
`DateLocale` (see [localization](localization.md)). Its weekday arrays are
Sunday first. The date and time patterns, the first weekday and the range
separator come from the provider's `formats`, `Formats::AMERICAN` by default
(Sunday first, a 12-hour clock) or `Formats::GERMAN` (Monday first, a 24-hour
clock, `14. September 2026`). Any language goes with any formats. This site is
English in German formats.
