Component · in flow
Date field
A day, typed or chosen in the kit's own calendar, over a native date field that keeps the value.
States
When we may call.
This day is taken.
You can change it later.
Languages
Plain HTML
React
The last day it counts.
Changes:
Usage
Astro:
---
import DateField from '@subfloor/astro/DateField.astro'
---
<DateField id="until" name="until" label="Valid until" value="2026-11-30"
min="2026-11-01" required />
<!-- In another language: set it on the page or around the field, and translate our words. -->
<div lang="cs">
<DateField id="do" name="do" label="Platí do" labels={{
open: 'Vybrat datum', close: 'Zavřít', previous: 'Předchozí měsíc',
next: 'Další měsíc', today: 'Dnes', clear: 'Vymazat',
invalid: 'Zadejte datum, například {example}.',
}} />
</div>React:
import { DateField } from '@subfloor/react'
// Always text such as '2026-11-30', or '' for none. Never a Date.
<DateField label="Valid until" value={until} onValueChange={setUntil}
min="2026-11-01" weekStart={1} labels={labels} />Markup
<div class="sf-field">
<label class="sf-field__label" for="until">Valid until</label>
<!-- data-week-start: 1 (Monday) to 7 (Sunday); data-labels: our words as JSON -->
<div class="sf-date" data-sf-date>
<input class="sf-field__control sf-date__native" type="date" id="until"
name="until" value="2026-11-30">
</div>
</div>
<script type="module">
import { createDateField, initDateFields } from '@subfloor/core'
initDateFields()
// After a script set the value: createDateField(element).sync()
</script>Behaviour
- The value is always text such as
2026-11-30, never aDate, so no time zone can change the day. A native field, hidden behind ours, keeps it: forms, reset,required,minandmaxwork as usual. - Type a day as the language of the page writes it (
lang, also around the field), or as2026-11-30, with the year first. The year needs four digits. It is read on Enter and when the field is left. Text that is no day stays and says so; until it is corrected, the field has no value, and the form is not sent. - On a computer, the button or Alt and the down arrow opens the calendar in a popover. On a phone or tablet (
(pointer: coarse)), a tap on the field opens it in a sheet that can be swiped down, without the keyboard. A day far away takes many taps there. With a keyboard attached to such a device, a day can be typed after moving to the field with Tab, but a tap or click on it still opens the sheet. - In the calendar, the arrow keys move by a day or a week, Home and End go to the ends of the week, Page Up and Page Down change the month, and with Shift the year. Enter or Space chooses, Escape closes. Each day is read out with its full date, and so is a month changed with a button.
- Clear is there only when the field has a day and is not
required. - In React, use
onValueChange. It also gets a day chosen before React hydrated.refis the native field; focusing it focuses ours.classNameis on both. - Weeks start as the language has it, or on Monday where the browser cannot tell. Set another day with
weekStart: 1 for Monday to 7 for Sunday. Our own words are English until you translate them withlabels. Names of days and months, and the browser’s own messages, are already in a language: the first two in that of the page, the messages in that of the browser. - In plain HTML, call
sync()after a script set the value. It follows attributes, the form’s reset, andinputandchangeevents of the native field by itself. A value outside the limits that a script sets shows its error below only once the user has changed the field, but the form is not sent. - Put the label beside the field, with
for, not around it: around it, presses in the calendar would count as presses on the label, and the calendar’s words as its name. autocompletestays on the native field. Ours is alwaysoff, so it offers no dates such as a birthday.
Without JavaScript
The browser’s own date field and picker. The kit’s field also waits while someone uses that one, and takes over when they leave it.
Customisation
:root {
--sf-calendar-selected-bg: var(--brand); /* keep 3:1 against the surface */
--sf-calendar-selected-color: white;
}| Token | Default |
|---|---|
--sf-touch-target | 44px |
--sf-popover-min-width | 12rem |
--sf-popover-max-width | min(22rem, 100vw - 2 * var(--sf-overlay-gutter)) |
--sf-popover-max-height | min(22rem, 70dvh) |
--sf-popover-offset | var(--sf-space-1) |
--sf-radius-popover | var(--sf-radius-control) |
--sf-shadow-popover | 0 8px 24px rgb(0 0 0 / 16%) |
--sf-field-border-color | #71717a |
--sf-field-font-size | 1rem |
--sf-field-gap | var(--sf-space-1) |
--sf-field-padding | var(--sf-space-3) |
--sf-field-short-width | 6rem |
--sf-field-suffix-gap | var(--sf-space-2) |
--sf-calendar-day-size | var(--sf-touch-target) |
--sf-calendar-padding | 6px |
--sf-calendar-selected-bg | var(--sf-button-primary-bg) |
--sf-calendar-selected-color | var(--sf-button-primary-color) |
Background
Content 1. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 2. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 3. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 4. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 5. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 6. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 7. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 8. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 9. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 10. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 11. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.
Content 12. Background text that only exists so there is something to scroll. When an overlay is open, this must stay exactly where it is, whatever the wheel, the keyboard or a finger does.