component
DateField
A date, picked from a Calendar. Select's field, showing the date, and a Calendar in a Popover under it when it's pressed.
Try it
Every variant
Default · Not errorDisabled · Not errorDefault · ErrorHover, press or tab to one to see the other 4 states.
import { DateField } from 'rost/components/date-field/DateField'
<DateField label="Invoice date" value={date} onValueChange={setDate} max={new Date()} />
// From and to
<DateField label="Report period" range={period} onRangeChange={setPeriod} /> src/components/date-field/DateField.tsx
import { useId, useRef, useState, type ReactNode } from 'react'
import { Calendar, type DateRange } from '../calendar/Calendar'
import { Popover } from '../popover/Popover'
import './date-field.css'
export interface DateFieldProps {
/** The field's name, small at the top. */
readonly label: ReactNode
/** The picked date. */
readonly value?: Date | null
readonly onValueChange?: (date: Date) => void
/** Picking a range, from and to, instead of one date. With it, `value` is left out. */
readonly range?: DateRange | null
/** Called with the range once both ends are picked. */
readonly onRangeChange?: (range: DateRange) => void
/** What the field says before there's a date. */
readonly placeholder?: string
readonly min?: Date
readonly max?: Date
/** Today, for the Calendar. The real today by default. */
readonly today?: Date
readonly locale?: string
/** One line under the field: help, or what to fix. */
readonly supportive?: ReactNode
/** Select's red. Say what's wrong in `supportive`. */
readonly error?: boolean
readonly disabled?: boolean
readonly id?: string
readonly className?: string
}
const b = 'rost-date-field'
/**
* A date, picked from a Calendar. Select's field as a button, and the
* Calendar in a Popover under it. Built from contracts/date-field.contract.yaml.
*/
export function DateField({ label, value = null, onValueChange, range, onRangeChange, placeholder, min, max, today, locale = 'en', supportive, error = false, disabled = false, id, className }: DateFieldProps) {
const made = useId()
const fieldId = id ?? made
const popId = `${fieldId}-calendar`
const helpId = `${fieldId}-help`
const button = useRef<HTMLButtonElement>(null)
const [open, setOpen] = useState(false)
const ranged = range !== undefined || onRangeChange !== undefined
// The range being picked in the Calendar, before both ends are in.
const [draft, setDraft] = useState<DateRange | null>(null)
const short = (d: Date, year = true) => d.toLocaleDateString(locale, { day: 'numeric', month: 'short', ...(year && { year: 'numeric' }) })
const text = ranged
? range?.end ? `${short(range.start, range.start.getFullYear() !== range.end.getFullYear())} – ${short(range.end)}` : placeholder ?? 'Pick dates'
: value ? short(value) : placeholder ?? 'Pick a date'
return (
<div className={[b, error && `${b}--error`, className].filter(Boolean).join(' ')}>
<span className={`${b}__outline`} aria-hidden="true" />
<button
ref={button}
id={fieldId}
type="button"
className={`${b}__field`}
disabled={disabled}
popoverTarget={popId}
aria-haspopup="dialog"
aria-expanded={open}
aria-invalid={error || undefined}
aria-describedby={supportive != null ? helpId : undefined}
>
{text}
</button>
<label className={`${b}__label`} htmlFor={fieldId}>{label}</label>
<span className={`${b}__chevron`} aria-hidden="true" />
{supportive != null && <span id={helpId} className={`${b}__supportive`}>{supportive}</span>}
<span className={`${b}__focus-ring`} aria-hidden="true" />
<Popover
fit
id={popId}
role="dialog"
aria-labelledby={fieldId}
onToggle={(e) => { const now = (e as unknown as ToggleEvent).newState === 'open'; setOpen(now); if (!now) setDraft(null) }}
>
{open && (
ranged ? (
<Calendar
autoFocus
range={draft ?? range ?? null}
today={today}
min={min}
max={max}
locale={locale}
onRangeChange={(r) => {
if (!r.end) { setDraft(r); return }
setDraft(null)
onRangeChange?.(r)
document.getElementById(popId)?.hidePopover()
button.current?.focus()
}}
/>
) : <Calendar
autoFocus
value={value}
today={today}
min={min}
max={max}
locale={locale}
onValueChange={(d) => {
onValueChange?.(d)
document.getElementById(popId)?.hidePopover()
button.current?.focus()
}}
/>
)}
</Popover>
</div>
)
}
The source for everything on this page: contracts/date-field.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: date-field
name: DateField
kind: component
status: review
summary: "A date, picked from a Calendar. Select's field, showing the date, and a Calendar in a Popover under it when it's pressed."
category: inputs
related: [ calendar, select, popover, input ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "752:50"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=752-50
extractedAt: "2026-11-17"
extractedBy: hand
frozenAt: "2026-11-17"
props:
label: { type: slot, required: true, notes: "The field's name, small at the top, as Select's is." }
value: { type: node, notes: "The picked date, a `Date`, or nothing." }
range: { type: node, notes: "For a from-and-to instead of one date: `{ start, end }`. The field shows both, like 1 Nov – 30 Nov 2026, and the Calendar picks a range. Use it or `value`, not both." }
placeholder: { type: string, default: Pick a date, notes: "What the field says before there's a date. Pick dates with `range`." }
min: { type: node, notes: "The first date that can be picked. Passed to the Calendar." }
max: { type: node, notes: "The last date that can be picked." }
locale: { type: string, default: en, notes: "How the date is written, and the Calendar's language." }
supportive: { type: slot, notes: "One line under the field: help, or what to fix when `error` is on." }
error: { type: boolean, default: false, notes: "Select's red: the edge, the label, the chevron and the help line." }
states: [ Default, Hover, Focus, Disabled ]
stateSelectors:
Focus: ":has(> .rost-date-field__field:focus-visible)"
Disabled: ":has(> .rost-date-field__field:disabled)"
elements:
root:
notes: "A box the size of Input, holding the parts, exactly as Select's. The button covers all of it, so a press anywhere opens the Calendar."
styles:
display: { value: block, assert: false }
position: { value: relative, assert: false }
height: { token: spacing/size/large, value: 56px }
width: { value: 208px, notes: "Just the size of the Figma frame, as Input's is. A field is as wide as its form." }
outline:
notes: "The field's fill and its 1px edge, on their own layer, as Input has them."
styles:
position: { value: absolute }
inset: { value: "0" }
border-style: { value: solid }
border-width: { token: spacing/outline/small, value: 1px }
border-radius: { token: spacing/radius/medium, value: 12px }
pointer-events: { value: none, assert: false }
label:
notes: "Select's label: placeholder type, 12px in from the edges. A `<label>` for the button."
styles:
position: { value: absolute }
top: { token: spacing/gap/small-medium, value: 12px }
left: { token: spacing/gap/small-medium, value: 12px }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/label/font-weight/regular, value: "400" }
font-size: { token: typography/placeholder/font-size, value: 10px }
line-height: { token: typography/placeholder/line-height, value: 12px }
letter-spacing: { token: typography/placeholder/letter-spacing, value: 0px }
pointer-events: { value: none, assert: false }
field:
notes: "A `<button>` over the whole box, showing the date where Select shows its value. It opens the Popover."
styles:
display: { value: block, assert: false }
width: { value: 100%, assert: false }
text-align: { value: left, assert: false }
white-space: { value: nowrap, assert: false }
position: { value: absolute }
inset: { value: "0" }
appearance: { value: none, assert: false }
background: { value: transparent, assert: false }
border: { value: none, assert: false }
outline: { value: none, assert: false }
cursor: { value: pointer, assert: false }
padding-top: { token: spacing/gap/large, value: 24px, notes: "The label's 12px and its 12px line above the value." }
padding-bottom: { token: spacing/gap/small-medium, value: 12px }
padding-left: { token: spacing/gap/small-medium, value: 12px }
padding-right: { token: spacing/size/medium, value: 40px, notes: "Room for the chevron and the 12px after it." }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/regular, value: "400" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
chevron:
notes: "Rost's chevron-down, 20px, drawn as a mask in Input's icon colour, 12px from the right edge."
styles:
position: { value: absolute }
top: { token: spacing/gap/medium-large, value: 20px, notes: "Centres the 20px chevron on the value line." }
right: { token: spacing/gap/small-medium, value: 12px }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
mask: { value: url(./icon-chevron.svg) center / contain no-repeat, untokenised: The icon file itself. }
pointer-events: { value: none, assert: false }
supportive:
notes: "Input's help line, 4px under the field. It sits outside the field's box, so it doesn't change the field's height."
styles:
position: { value: absolute }
left: { token: spacing/gap/small-medium, value: 12px }
top: { value: "calc(var(--spacing-size-large) + var(--spacing-gap-2xsmall))", untokenised: "Composed from tokens: the field's height plus spacing/gap/2xsmall." }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/label/font-weight/medium, value: "500" }
font-size: { token: typography/placeholder/font-size, value: 10px }
line-height: { token: typography/placeholder/line-height, value: 12px }
letter-spacing: { token: typography/placeholder/letter-spacing, value: 0px }
white-space: { value: nowrap, assert: false }
focus-ring:
notes: Input's ring, 4px outside the field.
styles:
display: { value: none, assert: false }
position: { value: absolute }
inset: { value: "calc(-1 * var(--spacing-gap-2xsmall))", untokenised: "Composed from a token: the ring sits spacing/gap/2xsmall outside the field." }
border-style: { value: solid }
border-width: { token: spacing/outline/medium, value: 2px }
border-radius: { token: spacing/radius/large, value: 16px }
pointer-events: { value: none, assert: false }
variants:
- when: { state: Default, error: false }
figmaNode: "752:3"
elements:
outline:
background: { token: select/default/background, value: "#060805" }
border-color: { token: select/default/outline, value: "#747573" }
label:
color: { token: select/default/label, value: "#999999" }
field:
color: { token: select/default/value, value: "#c2c7c3" }
chevron:
background: { token: select/default/chevron, value: "#00d669" }
supportive:
color: { token: select/default/supportive, value: "#999999" }
- when: { state: Hover, error: false }
figmaNode: "752:9"
elements:
outline:
background: { token: select/hover/background, value: "#171717" }
border-color: { token: select/hover/outline, value: "#999999" }
label:
color: { token: select/hover/label, value: "#d3d9d5" }
field:
color: { token: select/hover/value, value: "#d3d9d5" }
chevron:
background: { token: select/hover/chevron, value: "#00b450" }
supportive:
color: { token: select/hover/supportive, value: "#d3d9d5" }
- when: { state: Focus, error: false }
figmaNode: "752:15"
elements:
outline:
background: { token: select/focus/background, value: "#060805" }
border-color: { token: select/focus/outline, value: "#747573" }
label:
color: { token: select/focus/label, value: "#999999" }
field:
color: { token: select/focus/value, value: "#c2c7c3" }
chevron:
background: { token: select/focus/chevron, value: "#00d669" }
supportive:
color: { token: select/focus/supportive, value: "#999999" }
focus-ring:
display: { value: block, assert: false }
border-color: { token: select/focus/focus-ring, value: "#00d669" }
- when: { state: Disabled, error: false }
figmaNode: "752:22"
elements:
outline:
background: { token: select/disabled/background, value: "#171717" }
border-color: { token: select/disabled/outline, value: "#3a3a3a" }
label:
color: { token: select/disabled/label, value: "#555555" }
field:
color: { token: select/disabled/value, value: "#555555" }
chevron:
background: { token: select/disabled/chevron, value: "#b6ffda" }
opacity: { token: opacity/soft, value: "0.16", notes: "As Input's icon does when it's disabled." }
supportive:
color: { token: select/disabled/supportive, value: "#555555" }
- when: { state: Default, error: true }
figmaNode: "752:28"
elements:
outline:
background: { token: select/negative/default/background, value: "#060805" }
border-color: { token: select/negative/default/outline, value: "#f2705f" }
label:
color: { token: select/negative/default/label, value: "#e93120" }
field:
color: { token: select/negative/default/value, value: "#999999" }
chevron:
background: { token: select/negative/default/chevron, value: "#e93120" }
supportive:
color: { token: select/negative/default/supportive, value: "#e93120" }
- when: { state: Hover, error: true }
figmaNode: "752:35"
elements:
outline:
background: { token: select/negative/hover/background, value: "#171717" }
border-color: { token: select/negative/hover/outline, value: "#e93120" }
label:
color: { token: select/negative/hover/label, value: "#f2705f" }
field:
color: { token: select/negative/hover/value, value: "#999999" }
chevron:
background: { token: select/negative/hover/chevron, value: "#e93120" }
supportive:
color: { token: select/negative/hover/supportive, value: "#e93120" }
- when: { state: Focus, error: true }
figmaNode: "752:42"
elements:
outline:
background: { token: select/negative/focus/background, value: "#060805" }
border-color: { token: select/negative/focus/outline, value: "#f2705f" }
label:
color: { token: select/negative/focus/label, value: "#e93120" }
field:
color: { token: select/negative/focus/value, value: "#c2c7c3" }
chevron:
background: { token: select/negative/focus/chevron, value: "#e93120" }
supportive:
color: { token: select/negative/focus/supportive, value: "#e93120" }
focus-ring:
display: { value: block, assert: false }
border-color: { token: select/negative/focus/focus-ring, value: "#00d669" }
guidance:
status: proposed
use:
- title: A date on a form
text: "An invoice's date, the day a payment arrived. It sits with Inputs and Selects and looks like them."
show: "state=Default, error=False"
avoid:
- title: A date typed from memory
text: "A birthday, or a year long ago: paging through months to get there is slow. That's an **Input**."
- title: The Calendar on the page
text: "When choosing the day is the whole task, show the **Calendar** itself, not behind a field."
behaviour: |-
It looks like Select, and uses Select's colours, so a form with both reads as one. Pressing it opens a Calendar in a Popover under it, on the picked month. Picking a day closes the Popover, puts the date in the field and the focus back on it. Esc or a click outside closes it without a change. The date is written the locale's way, like Nov 17, 2026.
With `range` it takes two dates: the first press in the Calendar is the start, the second the end, and the Popover closes then. The field shows both, with the year once when they share it.
accessibility:
element: "A `<button>` named by its `<label>`, with `aria-haspopup=\"dialog\"` and `aria-expanded`. The Popover holds the Calendar, which has its own grid."
name: "`label`. The button says the date too, so a screen reader hears both: Invoice date, Nov 17, 2026."
keyboard: "Tab reaches it, Enter or Space opens it with the focus on the picked day, and the Calendar's keys work from there. Esc closes it."
focus: "`focus-ring` around the field, on `:focus-visible`."
error: "`error` sets `aria-invalid` and ties the help line to the button. The words say what's wrong."
colour: "Select's: the edge is 4.3:1 on the dark page."
content: "A label that names the date: Invoice date, not Date."
Install
npx github:Runceanu/rost add date-field It lands in src/rost/date-field/, with what it needs and its contract. Install has the rest.
When to use
A date on a form
An invoice's date, the day a payment arrived. It sits with Inputs and Selects and looks like them.
When not to use
A date typed from memory
A birthday, or a year long ago: paging through months to get there is slow. That's an Input.
The Calendar on the page
When choosing the day is the whole task, show the Calendar itself, not behind a field.
Behaviour
It looks like Select, and uses Select's colours, so a form with both reads as one. Pressing it opens a Calendar in a Popover under it, on the picked month. Picking a day closes the Popover, puts the date in the field and the focus back on it. Esc or a click outside closes it without a change. The date is written the locale's way, like Nov 17, 2026.
With range it takes two dates: the first press in the Calendar is the start, the second the end, and the Popover closes then. The field shows both, with the year once when they share it.
Accessibility
- Element
A
<button>named by its<label>, witharia-haspopup="dialog"andaria-expanded. The Popover holds the Calendar, which has its own grid. - Name
label. The button says the date too, so a screen reader hears both: Invoice date, Nov 17, 2026. - Keyboard
Tab reaches it, Enter or Space opens it with the focus on the picked day, and the Calendar's keys work from there. Esc closes it.
- Focus
focus-ringaround the field, on:focus-visible. - Error
errorsetsaria-invalidand ties the help line to the button. The words say what's wrong. - Colour
Select's: the edge is 4.3:1 on the dark page.
Content
A label that names the date: Invoice date, not Date.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
label | slot | | |
value | node | | |
range | node | | |
placeholder | string | | Pick a date |
min | node | | |
max | node | | |
locale | string | | en |
supportive | slot | | |
error | boolean | | false |
States: Default, Hover, Focus, Disabled.
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
height56pxspacing/size/large -
width208pxno token yet
displayblock · positionrelative
outline
-
border-stylesolidno token yet -
border-width1pxspacing/outline/small -
border-radius12pxspacing/radius/medium
positionabsolute · inset0 · pointer-eventsnone
label
-
top12pxspacing/gap/small-medium -
left12pxspacing/gap/small-medium -
font-family'General Sans Variable'font-family/base -
font-weight400typography/label/font-weight/regular -
font-size10pxtypography/placeholder/font-size -
line-height12pxtypography/placeholder/line-height -
letter-spacing0pxtypography/placeholder/letter-spacing
positionabsolute · pointer-eventsnone
field
-
padding-top24pxspacing/gap/large -
padding-bottom12pxspacing/gap/small-medium -
padding-left12pxspacing/gap/small-medium -
padding-right40pxspacing/size/medium -
font-family'General Sans Variable'font-family/base -
font-weight400typography/paragraph/font-weight/regular -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing
displayblock · width100% · text-alignleft · white-spacenowrap · positionabsolute · inset0 · appearancenone · backgroundtransparent · bordernone · outlinenone · cursorpointer
chevron
-
top20pxspacing/gap/medium-large -
right12pxspacing/gap/small-medium -
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
maskurl(./icon-chevron.svg) center / contain no-repeaton purpose: The icon file itself.
positionabsolute · pointer-eventsnone
supportive
-
left12pxspacing/gap/small-medium -
topcalc(var(--spacing-size-large) + var(--spacing-gap-2xsmall))on purpose: Composed from tokens: the field's height plus spacing/gap/2xsmall. -
font-family'General Sans Variable'font-family/base -
font-weight500typography/label/font-weight/medium -
font-size10pxtypography/placeholder/font-size -
line-height12pxtypography/placeholder/line-height -
letter-spacing0pxtypography/placeholder/letter-spacing
positionabsolute · white-spacenowrap
focus-ring
-
border-stylesolidno token yet -
border-width2pxspacing/outline/medium -
border-radius16pxspacing/radius/large
displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone
Changes by variant
7 variants. Each table is what one thing changes with: a column per error, a row per property. Where every row starts with the same token path, it's written once, under the property.
Follows error
Focus
| Property | Not error | Error |
|---|---|---|
focus-ring.border-colorselect/… | focus/focus-ring #00d669 | negative/focus/focus-ring #00d669 |
Follows state and error
Not error
| Property | Default | Hover | Focus | Disabled |
|---|---|---|---|---|
chevron.backgroundselect/… | default/chevron #00d669 | hover/chevron #00b450 | focus/chevron #00d669 | disabled/chevron #b6ffda |
field.colorselect/… | default/value #c2c7c3 | hover/value #d3d9d5 | focus/value #c2c7c3 | disabled/value #555555 |
label.colorselect/… | default/label #999999 | hover/label #d3d9d5 | focus/label #999999 | disabled/label #555555 |
outline.backgroundselect/… | default/background #060805 | hover/background #171717 | focus/background #060805 | disabled/background #171717 |
outline.border-colorselect/… | default/outline #747573 | hover/outline #999999 | focus/outline #747573 | disabled/outline #3a3a3a |
supportive.colorselect/… | default/supportive #999999 | hover/supportive #d3d9d5 | focus/supportive #999999 | disabled/supportive #555555 |
Error
| Property | Default | Hover | Focus | Disabled |
|---|---|---|---|---|
chevron.backgroundselect/negative/… | default/chevron #e93120 | hover/chevron #e93120 | focus/chevron #e93120 | · |
field.colorselect/negative/… | default/value #999999 | hover/value #999999 | focus/value #c2c7c3 | · |
label.colorselect/negative/… | default/label #e93120 | hover/label #f2705f | focus/label #e93120 | · |
outline.backgroundselect/negative/… | default/background #060805 | hover/background #171717 | focus/background #060805 | · |
outline.border-colorselect/negative/… | default/outline #f2705f | hover/outline #e93120 | focus/outline #f2705f | · |
supportive.colorselect/negative/… | default/supportive #e93120 | hover/supportive #e93120 | focus/supportive #e93120 | · |
Only in some variants
These don't change: they're just set in some variants and not others.
Disabled
-
chevron.opacity0.16opacity/soft
Focus
-
focus-ring.displayblocklayout