SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

DateField

A labeled, described and validated date field.

Today — this claim posts in the current period.

View code
tsx
let today = new Date();
let { min, max } = quarterBounds(today);
let value = toDayKey(today, systemTimeZone());

function pickDate(event: Event) {
	if (event.target instanceof HTMLInputElement) value = event.target.value;
	void handle.update();
}

<DateField
	name="transactionDate"
	value={value}
	min={min}
	max={max}
	required
	autoComplete="off"
	mix={on("change", pickDate)}
>
	<DateField.Label>Transaction date</DateField.Label>
	<DateField.Description>{relativeDayHint(parseDayValue(value), today)}</DateField.Description>
</DateField>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add date-field

Usage

typescript
import { DateField } from "@sdxc/ui";

Renders a date field: the native date control, laid out with the parts the caller writes. An error, from .Error or an enclosing Form's issue for name, marks the control invalid and recolors its border and ring to the danger tone.

Examples

Bounded with a hint

Your Acme plan can start on any day in 2026.

View code
tsx
<DateField name="startDate" min="2026-01-01" max="2026-12-31">
	<DateField.Label>Start date</DateField.Label>
	<DateField.Description>Your Acme plan can start on any day in 2026.</DateField.Description>
</DateField>

Invalid value

Pick a due date after today.
View code
tsx
<DateField name="dueDate" defaultValue="2026-07-20">
	<DateField.Label>Due date</DateField.Label>
	<DateField.Error>Pick a due date after today.</DateField.Error>
</DateField>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
color"brand" | "neutral" | "success" | "warning" | "danger"—NoSemantic color role for the control's focus ring. Defaults to "neutral" when omitted.
autoFocusboolean—NoNative autofocus. Defaults to true for the first invalid field of an enclosing Form's issues, landing keyboard focus on the problem after a server round-trip; pass it explicitly to override for this field.
namestring—NoNative name; it also finds the enclosing Form's issue for this field.
valuestring—NoCurrent value, in YYYY-MM-DD form, for a control a consumer tracks itself.
defaultValuestring—NoInitial value, in YYYY-MM-DD form, for a control left to the platform's own uncontrolled state.
minstring—NoEarliest accepted date, in YYYY-MM-DD form.
maxstring—NoLatest accepted date, in YYYY-MM-DD form.
stepnumber—NoGranularity, in days, the control's value must fall on.
requiredboolean—No
disabledboolean—No
readOnlyboolean—No
autoCompletestring—NoNative autofill hint, e.g. "bday".
childrenRemixNode—NoThe field's parts: .Label, .Description and .Error. The control follows the caption, and the rest keep their order.

Also accepts everything in TagProps<"div">.

Types

NameValuesWhat it decides
Color"brand" | "neutral" | "success" | "warning" | "danger"Semantic color role for the control's keyboard focus ring, each mapped to its matching --ui-* variables.
@sdxc/ui

Can’t find it? Contact us