sdxc

Type to search, or start from one of these:

DateRangePicker

A paired-field date range control built on DateField.

Pick both dates to see the length of the stay.

View code
let checkIn = "";
let checkOut = "";

// The fields own their values; the island only reads them back, so nothing it
// renders can overwrite a date the reader picked.
function readFields(event: Event) {
	let field = event.target as HTMLInputElement;
	if (field.name === "checkIn") checkIn = field.value;
	else if (field.name === "checkOut") checkOut = field.value;
	else return;
	void handle.update();
}

<DateRangePicker mix={[on<HTMLDivElement, "change">("change", readFields)]}>
	<Label htmlFor="checkIn">Dates of stay</Label>
	<DateRangePicker.Group>
		<Input id="checkIn" type="date" name="checkIn" aria-label="Check in" />
		<Input id="checkOut" type="date" name="checkOut" aria-label="Check out" />
	</DateRangePicker.Group>
	<Description>
		{stayLengthHint(parseDayValue(checkIn), parseDayValue(checkOut))}
	</Description>
</DateRangePicker>

Installation

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

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

Usage

import { DateRangePicker } from "@sdxc/ui";

Renders DateRangePicker's root. Leaving children unset renders two independent DateField instances side by side under a native role="group", each aligned to its own start edge so a validation message under one never shifts the other's label; composing DateRangePicker.Group as children instead joins the two fields into one row and leaves every field prop above unread.

Examples

<DateRangePicker>
	<Label htmlFor="tripStart">{t("form.trip.label")}</Label>
	<DateRangePicker.Group>
		<Input id="tripStart" type="date" name="tripStart" aria-label={t("form.trip.start")} />
		<Input id="tripEnd" type="date" name="tripEnd" aria-label={t("form.trip.end")} />
	</DateRangePicker.Group>
</DateRangePicker>

Props

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

PropTypeDescription
color?ColorSemantic color role for the fallback pair's focus rings. Read only when children is unset.
startLabel?RemixNodeThe start-date field's caption, rendered through DateField. Read only when children is unset.
endLabel?RemixNodeThe end-date field's caption, rendered through DateField. Read only when children is unset.
startDescription?RemixNodeSupporting copy beneath the start-date field. Read only when children is unset.
endDescription?RemixNodeSupporting copy beneath the end-date field. Read only when children is unset.
startErrorMessage?RemixNodeValidation message beneath the start-date field. Read only when children is unset.
endErrorMessage?RemixNodeValidation message beneath the end-date field. Read only when children is unset.
startName?stringNative name submitted with an enclosing form for the start-date field.
endName?stringNative name submitted with an enclosing form for the end-date field.
startValue?stringCurrent start-of-range value, in YYYY-MM-DD form, for a fallback pair a consumer tracks itself.
endValue?stringCurrent end-of-range value, in YYYY-MM-DD form, for a fallback pair a consumer tracks itself.
startDefaultValue?stringInitial start-of-range value, in YYYY-MM-DD form, for a fallback pair left to the platform's own uncontrolled state.
endDefaultValue?stringInitial end-of-range value, in YYYY-MM-DD form, for a fallback pair left to the platform's own uncontrolled state.
min?stringEarliest accepted date, in YYYY-MM-DD form, read by both of the fallback pair's fields.
max?stringLatest accepted date, in YYYY-MM-DD form, read by both of the fallback pair's fields.
step?numberGranularity, in days, both of the fallback pair's values must fall on.
required?booleanMarks both of the fallback pair's fields required for their enclosing form.
disabled?booleanMarks both of the fallback pair's fields inert and excluded from the tab order.
readOnly?booleanMarks both of the fallback pair's fields' values fixed, while keeping them focusable and included in form submission.
autoComplete?stringNative autofill hint for both of the fallback pair's fields.
parts?PartsPropsPer-part styling for the fallback pair's internally composed DateField instances. Read only when children is unset.
children?RemixNodeThe joined layout — typically a Label and a DateRangePicker.Group — rendered in place of the paired fields, leaving every field above unread when set.

Also accepts everything in Omit<TagProps<"div">, "children">.