Calendar unstable
A controlled calendar for picking a date, showing one month or several
consecutive months. Pass the selected date as value, the first visible
month as month, the number of months as months and the current day as
today. Handle Picked to update value and RequestedMonth to update
month. Your view supplies the markup; the component computes the grid
dates and attributes and manages keyboard navigation and focus.
Anatomy
| Part | Element |
|---|---|
root |
any element, around the header and the grids |
heading |
any element, showing the month's title |
previous |
<button> |
next |
<button> |
grid |
<table> |
weekday |
<th> inside the grid header |
cell |
<td> inside the grid body |
day |
<button> inside each cell |
root, previous, next, weekday and weekdays (short and long names
in display order) are shared. The nonempty months array holds each
month's month (its normalized first day), title (localized month and
year), weeks (DateTime.Utc[][], whole weeks) and
its heading, grid, cell and day parts. Use each month's heading
and grid together, with its cell and day parts inside that grid.
root, heading, previous, next and grid take the consumer's
builder and return it. weekday({ element, index }) takes the column index
(0 to 6), cell({ element, date }) takes the cell's date, and
day({ element, date, unavailable? }) takes the day's date and an optional
unavailable flag. No part adds markup.
Inside a Field, apply field.group to root, field.member to each
day, and pass disabled: field.disabled.
Date values
Every date prop accepts any DateTime (DateTime.Utc or
DateTime.Zoned) and is normalized with DateTime.removeTime to a
DateTime.Utc at midnight UTC. A Zoned value uses its calendar day in
its own time zone; a Utc value uses its UTC day. Because a UTC "now"
gives the UTC day, obtain today from DateTime.nowInCurrentZone or
another zoned DateTime. Every date the component emits or exposes in part
values is a normalized DateTime.Utc, and all localized formatting uses
timeZone: "UTC" so formatting preserves the normalized day.
Data attributes
Each present with an empty value or absent:
root,heading,grid:data-disabled,data-readonlyprevious,next:data-disabledday:data-selected,data-today,data-outside-month,data-unavailable,data-disabled,data-focused
Keyboard
When a grid has an enabled day, one day across all grids sits in the
page's Tab order (tabindex="0"); the rest have tabindex="-1".
- ArrowLeft / ArrowRight move by one day (swapped in a right-to-left layout)
- ArrowUp / ArrowDown move by one week
- Home / End move to the start / end of the week
- PageUp / PageDown move by one month
- Shift + PageUp / Shift + PageDown move by one year
- Enter and Space activate the focused day natively
Unavailable days stay focusable with aria-disabled="true", are not
skipped by arrow keys, and emit nothing when pressed. Days outside min
and max are natively disabled, and keyboard navigation clamps to the
range. Moves between shown months stay in the calendar. Moves that leave
them emit RequestedMonth with the first month shifted the least that
shows the target; if the consumer leaves month unchanged, focus stays
where it was. When month or months changes while a day has focus,
focus moves through root to the new tab stop without leaving the
calendar, unless the focused day is still shown in the same grid. Keep the
same root element mounted across month changes; the grids and days can
be replaced. If no shown day is in range, a visible day from an adjacent
month can receive focus.
Several months
A day outside its grid's month that another grid shows, such as December
1st in November's grid, is a copy: natively disabled with
data-disabled, and never the tab stop. Outside days before the first
month and after the last behave as in a single month. previous and
next step one month.
Usage
The calendar follows the nearest DirectionProvider above it or, without
one, the root's CSS direction. The server formats with its own default
locale, which may differ from the browser's; pass locale when rendering
on a server.
Example A controlled two-month calendar whose selected date and first month live in the consumer's Model
import { UiSchema } from "effect/ui"import { Html, HtmlServer } from "effect/ui/html"import { Calendar } from "effect/ui/kit"import { DateTime, Effect, Schema } from "effect"
const BookingMessage = UiSchema.TaggedEnum({ PickedDate: { date: Schema.DateTimeUtc }, RequestedMonth: { month: Schema.DateTimeUtc }})
const Booking = Html.component({ name: "Booking", model: Schema.Struct({ date: Schema.NullOr(Schema.DateTimeUtc), month: Schema.DateTimeUtc }), message: BookingMessage}).make({ init: () => ({ date: DateTime.makeUnsafe("2026-11-15T00:00:00Z"), month: DateTime.makeUnsafe("2026-11-01T00:00:00Z") }), update: { PickedDate: ($, { date }) => $.evolve({ date }), RequestedMonth: ($, { month }) => $.evolve({ month }) }, view: (h, model) => Calendar(h, { props: { value: model.date, month: model.month, months: 2, today: DateTime.makeUnsafe("2026-11-26T00:00:00Z"), locale: "en-US" }, onEmit: { Picked: ({ date }) => BookingMessage.PickedDate({ date }), RequestedMonth: ({ month }) => BookingMessage.RequestedMonth({ month }) }, view: (calendar) => calendar.root(h.div.class("calendar")).children( calendar.previous(h.button).children("Prev"), calendar.next(h.button).children("Next"), ...calendar.months.map((month) => h.section( month.heading(h.h2).children(month.title), month.grid(h.table.class("grid")).children( h.thead( h.tr( ...calendar.weekdays.map((day, index) => calendar.weekday({ element: h.th, index }).children(day.short) ) ) ), h.tbody( ...month.weeks.map((week) => h.tr( ...week.map((date) => month.cell({ element: h.td, date }).children( month.day({ element: h.button, date }).children( String(DateTime.getPartUtc(date, "day")) ) ) ) ) ) ) ) ) ) ) })})
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Booking, {}))if (!/<table class="grid"[^>]* role="grid"/.test(html)) throw new Error("the grid isn't a styled grid")if (!/<td[^>]* role="gridcell"[^>]* aria-selected="true"/.test(html)) throw new Error("no selected cell")if (html.match(/role="grid"/g)?.length !== 2) throw new Error("not two grids")Components
A headless calendar. Call it with the consumer's h, the props,
onEmit, and a view closure that draws root, previous, next,
weekday, and each entry of months: its heading, grid, cell and
day.
Details
The parts object also exposes weekdays, and each entry of months its
month, title and weeks.
Each part's owned attributes win over values the consumer set on the builder before applying the part, including attributes a state leaves absent:
root:tabindex="-1",data-disabledanddata-readonlyheading:id,aria-live="polite",data-disabledanddata-readonlyprevious,next:type="button",disabled,aria-disabledanddata-disabled(plus a fallbackaria-labelwhen the button has no accessible name)grid:role="grid",aria-labelledby(appending the heading's id),aria-disabled,aria-readonly,data-disabledanddata-readonlyweekday:scope="col"andabbrcell:role="gridcell"andaria-selectedday:type="button",tabindex,disabled,aria-label,aria-disabled,aria-current,data-selected,data-today,data-outside-month,data-unavailable,data-disabledanddata-focused
weekday throws when index is not an integer between 0 and 6.
History restore saves nothing of the calendar's transient focus state:
after Back, forward or a reload it starts from init.
Signature
declare const Calendar: Headless<{ readonly disabled?: boolean; readonly firstDayOfWeek?: 0 | 1 | 2 | 5 | 3 | 4 | 6; readonly locale?: string | readonly Array<string>; readonly max?: Utc | Zoned; readonly min?: Utc | Zoned; readonly month: Utc | Zoned; readonly months?: number; readonly readOnly?: boolean; readonly today: Utc | Zoned; readonly value: Utc | Zoned | null;}, { readonly _tag: "Picked"; readonly date: Utc;} | { readonly _tag: "RequestedMonth"; readonly month: Utc;}, { months: readonly [{ cell: <B extends Keyed<"td">>(__namedParameters: { readonly date: DateTime; readonly element: B; }) => ReturnType<B["attr"]> & Pick<Part<"td", [date: Utc], never>, "~R">; day: <B extends Keyed<"button">>(__namedParameters: { readonly date: DateTime; readonly element: B; readonly unavailable?: boolean; }) => ReturnType<B["attr"]> & Pick<Part<"button", [date: Utc, key: string, unavailable: boolean, gridMonth: Utc], never>, "~R">; grid: Part<"table", [], never>; heading: Part<string, [], never>; month: Utc; title: string; weeks: readonly Array<readonly Array<Utc>>; }, { cell: <B extends Keyed<"td">>(__namedParameters: { readonly date: DateTime; readonly element: B; }) => ReturnType<B["attr"]> & Pick<Part<"td", [date: Utc], never>, "~R">; day: <B extends Keyed<"button">>(__namedParameters: { readonly date: DateTime; readonly element: B; readonly unavailable?: boolean; }) => ReturnType<B["attr"]> & Pick<Part<"button", [date: Utc, key: string, unavailable: boolean, gridMonth: Utc], never>, "~R">; grid: Part<"table", [], never>; heading: Part<string, [], never>; month: Utc; title: string; weeks: readonly Array<readonly Array<Utc>>; }]; next: Part<"button", [], never>; previous: Part<"button", [], never>; root: Part<string, [], never>; weekday: <B extends Keyed<"th">>(__namedParameters: { readonly element: B; readonly index: number; }) => ReturnType<B["attr"]> & Pick<Part<"th", [index: number], never>, "~R">; weekdays: readonly Array<CalendarWeekdayName>;}, never, never, never, never, never, never, { readonly focused: boolean; readonly focusedDay: Utc | null; readonly pendingFocus: Utc | null; readonly pickedDay: Utc | null; readonly rtl: boolean; readonly shownMonth: Utc; readonly shownMonths: number;}, { readonly _tag: "FoundDirection"; readonly rtl: boolean;} | { readonly _tag: "ClickedDay"; readonly date: Utc; readonly keyboard: boolean; readonly unavailable: boolean;} | { readonly _tag: "ClickedStep"; readonly months: -1 | 1;} | { readonly _tag: "FocusedDay"; readonly date: Utc;} | { readonly _tag: "BlurredDay";} | { readonly _tag: "PressedKey"; readonly move: "previousDay" | "nextDay" | "previousWeek" | "nextWeek" | "startOfWeek" | "endOfWeek" | "previousMonth" | "nextMonth" | "previousYear" | "nextYear";} | { readonly _tag: "SyncedMonth";} | { readonly _tag: "ParkedFocus"; readonly date: Utc;}, QueryEntries<{}, {}>>Models
What a Calendar emits.
Signature
type CalendarEvents = typeof CalendarEvents.TypeThe props of a Calendar.
Signature
type CalendarProps = typeof CalendarProps.TypeShort and long localized names for a day of the week in Calendar.
Signature
type CalendarWeekday = CalendarWeekdayNameSchemas
CalendarEvents
unstableEvents emitted by Calendar.
Details
Picked: emitted when the user presses an enabled, available day while notreadOnly. Carries the normalized midnight-UTCdate.RequestedMonth: emitted when the user pressespreviousornextor navigates with the keyboard outside the shown months. Carries the normalized first day of the requested firstmonth.
Signature
declare const CalendarEvents: TaggedEnum<{ Picked: TaggedStruct<"Picked", { readonly date: DateTimeUtc; }>; RequestedMonth: TaggedStruct<"RequestedMonth", { readonly month: DateTimeUtc; }>;}>CalendarProps
unstableProps for a Calendar.
Details
value: the selected date, ornullfor none. Normalized withDateTime.removeTime.month: any date in the first month to display. Controlled so consumers can jump to a month and load its availability.months: how many consecutive months to show, a positive integer. Defaults to1.today: the current day, passed as a prop soinitstays pure and server HTML matches the client. PreferDateTime.nowInCurrentZoneor another zonedDateTime.minandmax: optional inclusive date bounds. Days outside the range are nativelydisabledand keyboard focus clamps to the bounds.firstDayOfWeek:0(Sunday) to6(Saturday). Defaults to the locale's first day viaIntl.Locale#getWeekInfo(including a-u-fw-extension), or Monday (1) when unavailable.locale: BCP 47 locale tag or tags for month titles, weekday names and day labels, which always use the Gregorian calendar of the grid. Defaults to the runtime's default locale.disabled: disables every button and suppresses all interaction.readOnly: allows focus, keyboard navigation and month requests while suppressingPicked.
Signature
declare const CalendarProps: Struct<{ readonly disabled: optional<Boolean>; readonly firstDayOfWeek: optional<Literals<readonly [0, 1, 2, 3, 4, 5, 6]>>; readonly locale: optional<Union<readonly [String, $Array<String>]>>; readonly max: optional<Union<readonly [DateTimeUtc, DateTimeZoned]>>; readonly min: optional<Union<readonly [DateTimeUtc, DateTimeZoned]>>; readonly month: Union<readonly [DateTimeUtc, DateTimeZoned]>; readonly months: optional<Number>; readonly readOnly: optional<Boolean>; readonly today: Union<readonly [DateTimeUtc, DateTimeZoned]>; readonly value: NullOr<Union<readonly [DateTimeUtc, DateTimeZoned]>>;}>