Skip to content
// EFFECT DAYS 2026

Html unstable

The HTML element vocabulary for effect/ui: element names on h, typed events with plain payloads, controlled properties, and refs typed by tag. The Commands that use those refs are in HtmlCommand, and document and window events in HtmlSubscription.

Details

Define HTML components with Html.component, which supplies the HTML vocabulary automatically, and type reusable pure HTML view functions with Html.H<Msg>. The module is also a View.Vocabulary<Html.Elements>.

Event handlers get plain data, never a DOM event: input has the field's value, keydown the key and the modifier keys, and submit the form's fields. A handler set with { preventDefault: true } cancels the browser's default when it produces a message and leaves it alone when it returns undefined, so it decides per event. A form's submit is always cancelled when it has a handler or uses the dialog method. Otherwise, the host leaves the browser default intact. Nothing stops an event's propagation: only the innermost element with a handler for an event gets it.

Use draggable(data) for a drag source and dropTarget({ accepts }).on("drop", handler) for a drop target. The host transfers the data and cancels browser defaults to allow accepted drops. dragenter and dragleave go to the active drop target only, not to every element the pointer crosses. Drag and drop needs a pointer, so provide a button or menu that sends the same message.

value, checked, selected and open are controlled: the host puts the Model's value back after every patch and after every event that could have changed it, so the element always shows what the Model says. While an input method composes text in a field, its value is left alone until compositionend. When the host writes a focused field's value, the selection stays where the user left it: a rejected edit puts it back, and a normalized value keeps it with the text around it. A details the browser toggled keeps its state until its toggle is sent.

The server renders attributes and the controlled properties only. Other properties are set in the browser, so set what the served HTML needs, such as hidden or disabled, with attr.

A dialog is closed, open, or open as a modal: .open(b) and .modal(b) set the same state, and the last call wins. A modal's close requests, such as Escape, come to cancel, and it closes when the Model says so. Forms in a dialog are the app's like any other, so read the choice in submit, not returnValue.

Any element can be a popover with .popover(mode, open), its state separate from a dialog's or details's open. A "manual" popover is controlled by the Model. An "auto" popover is followed: the browser closes it on Escape, a click outside or another popover opening, toggle reports it, and the Model must follow. Position a popover next to its trigger with CSS anchor positioning.

attr and attrs check role against AriaRole, and aria-* names and values against AriaAttributes, so role="tab-panel" or aria-checked="yes" doesn't compile. Other names take any string. Write a boolean state as ${open}.

SVG tags have builders of their own, such as h.svg, h.path and h.circle, with id, class, style, events and children as on HTML elements. attr and attrs check SVG's case-sensitive attribute names by tag, so viewbox or strok-width doesn't compile. SVG's text is h.svgText, since h.text makes a text node.

The HTML renderers omit href, src, action, formaction, xlink:href and data attributes containing javascript: or vbscript: URLs. Setting a built-in element's href, src, action, formAction or data property to a blocked URL removes its reflected attribute instead. Custom element properties are unchanged. These checks apply to server rendering, browser updates, hydration and head attributes. For set, animate and animateTransform elements, the renderers also omit to, from and by attributes containing blocked URLs, and the entire values attribute if any semicolon-separated item is blocked. These animation checks apply regardless of attributeName. Scheme checks ignore case, ASCII controls and spaces; relative URLs and other schemes pass through unchanged.

Example A controlled text field

import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { Schema } from "effect"
const Message = UiSchema.TaggedEnum({ UpdatedDraft: { value: Schema.String }, SubmittedForm: {} })
const NewTodo = Html.ref("NewTodo", "input")
const Form = Html.component({
name: "Form",
model: Schema.String,
message: Message
}).make({
init: () => "",
update: (_, message) => (message._tag === "UpdatedDraft" ? message.value : ""),
view: (h, draft) =>
h.form.on("submit", Message.SubmittedForm()).children(
h.input.ref(NewTodo).attr("aria-label", "New todo").value(draft)
.on("input", ({ value }) => Message.UpdatedDraft({ value })),
h.button.attr("type", "submit").children("Add")
)
})

Example Sending on Enter, keeping Shift+Enter's new line

import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { Schema } from "effect"
const Message = UiSchema.TaggedEnum({ UpdatedDraft: { value: Schema.String }, PressedEnter: {} })
const Composer = Html.component({
name: "Composer",
model: Schema.String,
message: Message
}).make({
init: () => "",
update: (_, message) => (message._tag === "UpdatedDraft" ? message.value : ""),
view: (h, draft) =>
h.textarea.attr("aria-label", "Message").value(draft)
.on("input", ({ value }) => Message.UpdatedDraft({ value }))
// Enter that ends an IME composition only confirms the text.
.on("keydown",
({ key, shift, composing }) =>
key === "Enter" && !shift && !composing ? Message.PressedEnter() : undefined,
{ preventDefault: true }
)
})

Example An icon

import { Html } from "effect/ui/html"
const ArrowIcon = <M>(h: Html.H<M>) =>
h.svg
.class("icon")
.attrs({
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
"stroke-width": "2",
"aria-hidden": "true"
})
.children(
h.circle.attrs({ cx: "12", cy: "12", r: "10" }),
h.path.attr("d", "M8 12h8m-3-3 3 3-3 3")
)
66 exports Since v4.2.0 Source

Attributes

AriaAttributes

interface unstable
Since v4.2.0

The WAI-ARIA states and properties, and their values. Token values are listed; ID references, numbers and text are any string. Write a boolean as ${open}; undefined removes the attribute.

Signature

interface AriaAttributes {
readonly "aria-activedescendant"?: string;
readonly "aria-atomic"?: AriaBoolean;
readonly "aria-autocomplete"?: "both" | "none" | "list" | "inline";
readonly "aria-braillelabel"?: string;
readonly "aria-brailleroledescription"?: string;
readonly "aria-busy"?: AriaBoolean;
readonly "aria-checked"?: AriaTristate;
readonly "aria-colcount"?: string;
readonly "aria-colindex"?: string;
readonly "aria-colindextext"?: string;
readonly "aria-colspan"?: string;
readonly "aria-controls"?: string;
readonly "aria-current"?: "date" | "time" | "page" | AriaBoolean | "step" | "location";
readonly "aria-describedby"?: string;
readonly "aria-description"?: string;
readonly "aria-details"?: string;
readonly "aria-disabled"?: AriaBoolean;
readonly "aria-errormessage"?: string;
readonly "aria-expanded"?: AriaBoolean;
readonly "aria-flowto"?: string;
readonly "aria-haspopup"?: "dialog" | AriaBoolean | "menu" | "listbox" | "tree" | "grid";
readonly "aria-hidden"?: AriaBoolean;
readonly "aria-invalid"?: AriaBoolean | "grammar" | "spelling";
readonly "aria-keyshortcuts"?: string;
readonly "aria-label"?: string;
readonly "aria-labelledby"?: string;
readonly "aria-level"?: string;
readonly "aria-live"?: "off" | "polite" | "assertive";
readonly "aria-modal"?: AriaBoolean;
readonly "aria-multiline"?: AriaBoolean;
readonly "aria-multiselectable"?: AriaBoolean;
readonly "aria-orientation"?: "horizontal" | "vertical";
readonly "aria-owns"?: string;
readonly "aria-placeholder"?: string;
readonly "aria-posinset"?: string;
readonly "aria-pressed"?: AriaTristate;
readonly "aria-readonly"?: AriaBoolean;
readonly "aria-relevant"?: string;
readonly "aria-required"?: AriaBoolean;
readonly "aria-roledescription"?: string;
readonly "aria-rowcount"?: string;
readonly "aria-rowindex"?: string;
readonly "aria-rowindextext"?: string;
readonly "aria-rowspan"?: string;
readonly "aria-selected"?: AriaBoolean;
readonly "aria-setsize"?: string;
readonly "aria-sort"?: "none" | "other" | "ascending" | "descending";
readonly "aria-valuemax"?: string;
readonly "aria-valuemin"?: string;
readonly "aria-valuenow"?: string;
readonly "aria-valuetext"?: string;
}

AriaRole

type unstable
Since v4.2.0

The concrete WAI-ARIA 1.2 roles and the Graphics ARIA roles, accepted by attr("role", role) and HtmlLocator role queries.

Signature

type AriaRole = "alert" | "alertdialog" | "application" | "article" | "banner" | "blockquote" | "button" | "caption" | "cell" | "checkbox" | "code" | "columnheader" | "combobox" | "complementary" | "contentinfo" | "definition" | "deletion" | "dialog" | "document" | "emphasis" | "feed" | "figure" | "form" | "generic" | "graphics-document" | "graphics-object" | "graphics-symbol" | "grid" | "gridcell" | "group" | "heading" | "img" | "insertion" | "link" | "list" | "listbox" | "listitem" | "log" | "main" | "marquee" | "math" | "menu" | "menubar" | "menuitem" | "menuitemcheckbox" | "menuitemradio" | "meter" | "navigation" | "none" | "note" | "option" | "paragraph" | "presentation" | "progressbar" | "radio" | "radiogroup" | "region" | "row" | "rowgroup" | "rowheader" | "scrollbar" | "search" | "searchbox" | "separator" | "slider" | "spinbutton" | "status" | "strong" | "subscript" | "superscript" | "switch" | "tab" | "table" | "tablist" | "tabpanel" | "term" | "textbox" | "time" | "timer" | "toolbar" | "tooltip" | "tree" | "treegrid" | "treeitem"

Attributes

interface unstable
Since v4.2.0

Attribute values for HTML builders, including custom attributes.

Details

An attribute object declared before the call needs satisfies Html.Attributes or as const to keep its literal values. For a value outside these types, pass attrs a Record<string, string>. A name from a generic type parameter needs widening, as in attr(name as string, value).

Names are checked as written, so write them in lowercase: HTML treats Role as role, but the check takes it for a custom attribute.

Signature

interface Attributes extends AriaAttributes {
[name: string]: string | undefined;
readonly role?: AriaRole;
}

classNames

unstable
Since v4.2.0

Joins class tokens with one space, skipping false, null, undefined and "".

When to use

Use to build a class string outside Element.class, such as an attribute other than class or a value passed to a child component.

Details

Tokens are kept as written: there is no splitting, deduplication or conflict resolution between utility classes. With no tokens left it returns "".

Signature

declare function classNames(...tokens: readonly Array<ClassToken>): string

Example Building a class string

import { Html } from "effect/ui/html"
const tabClass = (active: boolean) => Html.classNames("tab", active && "tab-active")
tabClass(true) // => "tab tab-active"
tabClass(false) // => "tab"

ClassToken

type unstable
Since v4.2.0

One class token for classNames and Element.class: a class string, or false, null or undefined for a class that is left out.

Details

true and numbers aren't tokens, which catches cond || "x" and count && "x" mistakes at compile time.

Signature

type ClassToken = string | false | null | undefined

Style

type unstable
Since v4.2.0

Inline styles with camelCase CSS property names and --custom properties.

Details

Property names come from the DOM library. Values are strings, not numbers; include units where CSS requires them. Use float rather than cssFloat. Empty strings and other falsy values omit the declaration.

Signature

type Style = { [K in Exclude<StyleProperty, "cssText" | "cssFloat"> | "float"]: StyleValue } & { [K in `--${string}`]: StyleValue }

StyleValue

type unstable
Since v4.2.0

An inline CSS value, or false, null or undefined to omit a declaration.

Signature

type StyleValue = string | false | null | undefined

Constructors

component

unstable
Since v4.2.0

Defines a component with the HTML element vocabulary already supplied, equivalent to Component.define({ ...options, elements: Html.vocabulary }).

Signature

declare const component: Component.Define<Elements>

Example A counter component

import { Html } from "effect/ui/html"
import { Schema } from "effect"
const Counter = Html.component({
name: "Counter",
model: Schema.Number,
message: Schema.Literal("ClickedIncrement")
}).make({
init: () => 0,
update: ($) => $.model + 1,
view: (h, count) => h.button.on("click", "ClickedIncrement").children(String(count))
})

Custom Elements

Since v4.2.0

Binds a custom element, a web component another library or your own code defines, to the HTML vocabulary, with typed properties and events.

When to use

Use when an element's contract is declarative: JavaScript properties go in and CustomEvents come out, as with most Lit, Stencil or Shoelace components. For an imperative API, such as a map or an editor you call methods on, use onMount.

Details

Each declared property gets a method that writes it as a JavaScript property, not an attribute, so arrays and objects work. The value is written as given: the Schema types it but doesn't encode it. The browser host writes it when it isn't === to the last one written, so a new array on every render is written on every render, and resets it to "", false or null when a render leaves it out. value, checked, selected and open are plain properties on a custom element, not controlled as on an input. The server renders none of them: the browser host sets them when it adopts the element.

Use on(event, handler) for declared events. The handler receives detail decoded by the event's Schema. Invalid detail is logged with console.error and sends no message. A missing or null detail that the Schema rejects is decoded again as {}, so Schema.Struct({}) declares an event without a payload. An event that doesn't bubble reaches the element's own handler only.

prop accepts declared properties, including names without a method (see CustomElementReserved). For a single tag registered in HTMLElementTagNameMap, it also infers writable fields beyond HTMLElement, excluding methods and callbacks. Inferred values use the fields' read types; explicit schemas take precedence. The registered class also types ref and onMount.

Declare schemas in properties for fluent property methods, callback properties, or accessors whose setters accept a different type from their getters' return types. Explicit schemas are also needed when the tag is absent from HTMLElementTagNameMap or has a union type.

HTML methods such as class, style and on("click", ...) remain available unless a declared property replaces them. The app must still register the element with customElements.define, often by importing its package.

Throws when tag isn't a custom element name, lowercase with a hyphen.

In a test, HtmlScene.fireElement and HtmlPlay.fireElement send a declared event with a typed detail.

Signature

declare function customElement<Tag extends string, P extends {
[name: string]: Top;
} = {}, E extends {
[event: string]: Decoder<unknown, never>;
} = {}>(config: CustomElementConfig<Tag, P, E>): CustomElementBinding<Tag, P, E>

Example A color picker web component

import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { Schema } from "effect"
const ColorPicker = Html.customElement({
tag: "hex-color-picker",
properties: { color: Schema.String },
events: { "color-changed": Schema.Struct({ value: Schema.String }) }
})
const Message = UiSchema.TaggedEnum({ ChangedColor: { color: Schema.String } })
const Swatch = Html.component({
name: "Swatch",
model: Schema.String,
message: Message
}).make({
init: () => "#1e1b4b",
update: { ChangedColor: (_, { color }) => color },
view: (h, color) =>
ColorPicker(h)
.class("swatch")
.color(color)
.on("color-changed", ({ value }) => Message.ChangedColor({ color: value }))
})

CustomElement

type unstable
Since v4.2.0

The builder of a custom element: CustomElementBuilder plus a method per declared property, named after it. Declared events are handled with on.

Details

A declared name wins over the HTML method of the same name, such as value or disabled, and is typed by its Schema. A wrong value for one of those reports "No overload matches this call", with the declared signature as the first overload. A name in CustomElementReserved gets no method.

Signature

type CustomElement<Msg, R = never, P = {}, E = {}, Tag extends string = string, Node = ElementOf<Tag>> = PropertyMethods<P> & CustomElementBuilder<Msg, R, P, E, Tag, Node>

CustomElementBinding

interface unstable
Since v4.2.0

A custom element bound with customElement. Call it with a view's h to get the element's root builder, which, like h.div, is also callable as shorthand for children.

Details

It takes an Html.H, so only an HTML view can use it. tag, properties and events are what it was defined with.

Signature

interface CustomElementBinding<Tag extends string, P, E> {
<Msg>(h: H<Msg>): Shorthand<CustomElement<Msg, never, TypesOf<P>, TypesOf<E>, Tag, ElementOf<Tag>>>;
readonly events: E;
readonly properties: P;
readonly tag: Tag;
}
Since v4.2.0

A custom element builder with typed properties and events. Declared event handlers receive the decoded detail as their payload.

Details

P maps each declared property to its value type and E each declared event to its detail. A declared event replaces an HTML event of the same name. Node defaults to HTMLElementTagNameMap[Tag], or HTMLElement for an unregistered tag, and types ref and onMount. CustomElement adds a method per declared property.

Signature

declare class CustomElementBuilder<out Msg, out R = never, in out P = {}, in out E = {}, out Tag extends string = string, in out Node = ElementOf<Tag>> extends Element<Msg, R, Omit<Events, keyof E> & E, Node, Tag> {
constructor<out Msg, out R = never, in out P = {}, in out E = {}, out Tag extends string = string, in out Node = ElementOf<Tag>>(tag: string);
readonly "~With"?: CustomElement<Msg, unknown, P, E, Tag, Node>;
}

CustomElementConfig

interface unstable
Since v4.2.0

What customElement takes: the element's tag, its JavaScript properties and its events, each described by a Schema. An event's Schema decodes its detail.

Signature

interface CustomElementConfig<Tag extends string, P, E> {
readonly events?: E;
readonly properties?: P;
readonly tag: Tag;
}
Since v4.2.0

The names that get no generated method on a custom element, because the builder already uses them: its own fields and core methods, such as content, key, ref, children and onMount, the names every object has, such as toString, plus id, class and style. Set a property with one of these names with prop.

Signature

type CustomElementReserved = keyof View.ContainerBuilder<any> | keyof typeof Object.prototype | "id" | "class" | "style"

Events

BlurPayload

interface unstable
Since v4.2.0

The payload of blur: whether the element that lost focus is disabled as the event fires.

Details

A user can't leave a disabled element, so disabled is true only when the element lost focus by being disabled, by its own disabled or by a <fieldset disabled> around it. A browser may send no blur at all for that. One that does can send it while a render is still writing, before the components below the disabled element have their new props, so a handler reads it here and not from its own state.

Signature

interface BlurPayload {
readonly disabled: boolean;
}

CompositionPayload

interface unstable
Since v4.2.0

The payload of compositionend on an input or textarea: the value the field holds once an input method has committed the composed text. The input events sent while it composed have composing set, so a handler can wait for this one to act on the text.

Signature

interface CompositionPayload {
readonly value: string;
}

DragEndPayload

interface unstable
Since v4.2.0

The payload of dragend, on the drag's source: whether the drag was dropped, on one of the app's drop targets or anywhere the browser reports it accepted, or was cancelled.

Signature

interface DragEndPayload {
readonly dropped: boolean;
}

DragOverPayload

interface unstable
Since v4.2.0

The payload of dragover: the pointer's position in the drop target's box, from its top-left corner, with the box's size.

Signature

interface DragOverPayload {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
}

DragSourceOptions

interface unstable
Since v4.2.0

A drag source, set with draggable: the strings it carries by type, and the drop effects it allows. Stored as the element's dragstart options.

Signature

interface DragSourceOptions extends EventOptions {
readonly data: Readonly<Record<string, string>>;
readonly effectAllowed?: EffectAllowed;
}

DropEffect

type unstable
Since v4.2.0

What a drop does, as a drop target shows it with the pointer: "copy", "move" or "link".

Signature

type DropEffect = "copy" | "move" | "link"

DropPayload

interface unstable
Since v4.2.0

The payload of drop: the dragged strings by type, the dragged files, and the pointer's position in the drop target's box, from its top-left corner, with the box's size. y < height / 2 tells the upper half from the lower.

Details

data holds every string type the drag carries, read when it's dropped, since a browser hides them until then. files is empty unless the drag carries files. A File isn't plain data: send it on to a Command, and keep plain facts about it, such as its name and size, in the Model, which must stay encodable.

Signature

interface DropPayload {
readonly data: Readonly<Record<string, string>>;
readonly files: readonly Array<File>;
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
}

DropTargetOptions

interface unstable
Since v4.2.0

A drop target, set with dropTarget: the drag types it accepts, matched without case with "Files" for files, and the drop effect it shows. Stored as the element's drop options.

Signature

interface DropTargetOptions extends EventOptions {
readonly accepts: readonly Array<string>;
readonly dropEffect?: DropEffect;
}

EffectAllowed

type unstable
Since v4.2.0

The drop effects a drag source allows. A drop target whose dropEffect the source doesn't allow can't take the drop.

Signature

type EffectAllowed = "none" | "copy" | "copyLink" | "copyMove" | "link" | "linkMove" | "move" | "all"

Events

interface unstable
Since v4.2.0

The events every HTML element has, with their payloads.

Details

focus, blur, pointerenter, pointerleave and scroll don't bubble: only the element they happen on gets them. The others go to the innermost element with a handler, except the drop target's events: dragenter, dragleave, dragover and drop go to the active drop target, as dropTarget describes.

pointerenter and pointerleave fire for every pointer, a tap included, so check pointerType to treat only a mouse or pen as hovering. An element drawn over another takes the pointer off the one below without a move and gives it back once gone: the leave and the enter then report the same position, which tells them from the pointer leaving and coming back.

pointerdown starts every press. A mousedown may not follow it: a touch may send no mouse events, and a pointerdown whose default was cancelled sends none.

pointermove is sent at most once per animation frame for each pointer, with its latest position, and its default can't be cancelled. A queued move is sent before its pointer's pointerdown or pointerup element event, and dropped at pointercancel, so the Model can revert at once. A capture-phase document subscriber hears the press or release before that move. To follow a drag outside the element, see PointerDownOptions.

Signature

interface Events {
readonly blur: BlurPayload;
readonly click: PointerPayload;
readonly contextmenu: PointerPayload;
readonly dblclick: PointerPayload;
readonly dragend: DragEndPayload;
readonly dragenter: {};
readonly dragleave: {};
readonly dragover: DragOverPayload;
readonly dragstart: {};
readonly drop: DropPayload;
readonly focus: FocusPayload;
readonly focusin: FocusWithinPayload;
readonly focusout: FocusOutPayload;
readonly keydown: KeyPayload;
readonly keyup: KeyPayload;
readonly mousedown: PointerPayload;
readonly mouseup: PointerPayload;
readonly paste: PastePayload;
readonly pointercancel: PointerPayload;
readonly pointerdown: PointerPayload;
readonly pointerenter: PointerPayload;
readonly pointerleave: PointerPayload;
readonly pointermove: PointerPayload;
readonly pointerup: PointerPayload;
readonly scroll: ScrollPayload;
readonly toggle: PopoverTogglePayload;
}

EventsOf

type unstable
Since v4.2.0

The events of one tag: the shared Events plus the tag's own.

Details

A dialog's cancel is a close request, such as Escape. For a modal the browser host cancels it, and the Model decides whether the dialog closes. cancelable is false when the browser won't let the request be cancelled, as after repeated cancelled requests: it closes the dialog itself, and close follows. close is sent after every close, the Model's included, except the close the browser host makes to switch a dialog between modal and non-modal, and a close the browser reports after the dialog was shown again.

A slot's slotchange carries no data, and hydration doesn't replay earlier slotchange events. Read the initial assigned nodes in a mount.

Signature

type EventsOf<K extends string> = Events & K extends "input" ? {
readonly change: InputPayload;
readonly input: InputPayload;
} : {} & K extends "textarea" | "select" ? {
readonly change: ValuePayload;
readonly input: ValuePayload;
} : {} & K extends "input" | "textarea" ? {
readonly compositionend: CompositionPayload;
readonly selectionchange: SelectionPayload;
} : {} & K extends "form" ? {
readonly reset: {};
readonly submit: SubmitPayload;
} : {} & K extends "details" ? {
readonly toggle: TogglePayload;
} : {} & K extends "dialog" ? {
readonly cancel: {
readonly cancelable: boolean;
};
readonly close: {
readonly returnValue: string;
};
readonly toggle: TogglePayload;
} : {} & K extends "img" | "iframe" | "video" | "audio" ? {
readonly error: {};
readonly load: {};
} : {} & K extends "slot" ? {
readonly slotchange: {};
} : {}

FocusOutPayload

interface unstable
Since v4.2.0

The payload of focusout: within, as for focusin, and disabled, as for blur, read from the descendant that lost focus.

Signature

interface FocusOutPayload extends FocusWithinPayload, BlurPayload {}

FocusPayload

interface unstable
Since v4.2.0

The payload of focus: whether the element shows a focus ring, as :focus-visible matches it as the event fires.

Details

A browser shows the ring for focus that came from the keyboard, and not for focus that came from a press, on the element or on another one whose handler moved focus. A component that opens on keyboard focus only reads it here. focusVisible is true where the browser can't tell.

Signature

interface FocusPayload {
readonly focusVisible: boolean;
}

FocusWithinPayload

interface unstable
Since v4.2.0

The payload of focusin and focusout: whether the other end of the move is inside the handler's element. For focusin that is where focus came from, and for focusout where it goes.

Details

An element that handles both can tell focus moving between its descendants from focus arriving or leaving: within is true for the first, and false for the second. Focus coming from or going to another window, or nowhere, counts as outside, as does an event a script dispatched with a relatedTarget that isn't a node, such as the window.

Signature

interface FocusWithinPayload {
readonly within: boolean;
}

InputPayload

interface unstable
Since v4.2.0

The payload of input and change on an input: its value, whether it's checked (a checkbox or radio button), the files it holds (a file input), and how the edit was made, as ValuePayload describes.

Details

files is empty unless the input is type="file". A File isn't plain data: send it on to a Command whose args type it with Schema.instanceOf(File), and keep plain facts about it, such as its name and size, in the Model, which must stay encodable. A Schema.File in the Model encodes the file's bytes into the page state.

Give a file input .value("") to report each choice once: the browser host sends the files in change, then empties the input, so choosing the same file again sends change again. Without .value the input keeps what the user chose.

Signature

interface InputPayload extends ValuePayload {
readonly checked: boolean;
readonly files: readonly Array<File>;
}

KeyPayload

interface unstable
Since v4.2.0

The payload of keydown and keyup. code is the physical key's KeyboardEvent.code, such as "KeyW", or "" when unavailable. composing is true while an input method composes text, including for the key that ends the composition, so a handler for Enter can leave it to the input method.

Details

repeat is true while a key is held down and firing auto-repeats.

editable is true when the event's innermost target (through open shadow roots) takes typed characters: a textarea, a select, an input other than button, checkbox, color, file, image, radio, range, reset or submit, or an element with isContentEditable true. A readonly field still counts. On element handlers editable describes the event's target, not the element holding the handler.

selectionStart and selectionEnd are the target's selection as the key finds it, as SelectionPayload describes.

Signature

interface KeyPayload extends SelectionPayload {
readonly alt: boolean;
readonly code: string;
readonly composing: boolean;
readonly ctrl: boolean;
readonly editable: boolean;
readonly key: string;
readonly meta: boolean;
readonly repeat: boolean;
readonly shift: boolean;
}

PastePayload

interface unstable
Since v4.2.0

The clipboard's plain text and files for a paste event. Missing or unreadable text becomes ""; missing or unreadable files become []. With { preventDefault: true }, returning a message cancels the paste; returning undefined allows the browser's default paste behavior.

Details

Send files to a Command and keep only metadata, such as name and size, in the Model. See InputPayload for file encoding details.

Signature

interface PastePayload {
readonly files: readonly Array<File>;
readonly text: string;
}

PointerDownOptions

interface unstable
Since v4.2.0

The options of pointerdown. With capturePointer: true, a press whose handler sends a message captures its pointer on the handler's element, so the element gets the press's pointermove, pointerup and pointercancel wherever the pointer goes.

Details

The browser releases the capture when the press ends. Capture sends the rest of the press to the element, so a click on a child goes to the element instead. A touch drag needs CSS touch-action: none on the element, or the browser scrolls and sends pointercancel.

Signature

interface PointerDownOptions extends EventOptions {
readonly capturePointer?: boolean;
}

PointerPayload

interface unstable
Since v4.2.0

The payload of click, dblclick, contextmenu, mousedown, mouseup and the pointer events: the button, the position in the viewport, the modifier keys, and the pointer.

Details

pointerType is "" for a click from the keyboard or a script. A pointer event reports its own. Otherwise the browser host reads it from the pointerdown before the event, since some browsers report a tap's click as a mouse's. A browser that sends no pointer events reports "mouse".

pointerId tells the pointers of a multi-touch apart, and is -1 for an event that carries none, such as a mousedown or a click from the keyboard.

Signature

interface PointerPayload {
readonly alt: boolean;
readonly button: number;
readonly ctrl: boolean;
readonly meta: boolean;
readonly pointerId: number;
readonly pointerType: PointerType;
readonly shift: boolean;
readonly x: number;
readonly y: number;
}

PointerType

type unstable
Since v4.2.0

What pressed an element: "mouse", "touch" or "pen", or "" for a click no pointer made, such as a button activated with Enter or Space.

Signature

type PointerType = "mouse" | "touch" | "pen" | ""

PopoverMode

type unstable
Since v4.2.0

How a popover behaves, set with popover.

Details

A "manual" popover is controlled: it shows what the Model says, and the browser host puts it back when anything else changes it. An "auto" popover is followed: the browser closes it on Escape, a click outside, another auto popover opening or a modal dialog opening, the host reports that as toggle, and the Model must follow. The host shows or hides an auto popover only when the Model's value changes, and never reverts the browser.

Signature

type PopoverMode = "manual" | "auto"

PopoverTogglePayload

interface unstable
Since v4.2.0

The payload of toggle, which any element can get as a popover: open is whether it's showing now, and newState and oldState are what the browser reported.

Details

Browsers coalesce the toggles queued for an element into one, from the first change's oldState to the latest newState, so the two can be equal, such as "closed" to "closed" for a popover shown and dismissed before the event. open and newState are the state when it's sent; follow them rather than the transition. On a details or dialog, a browser without ToggleEvent gets states derived from open.

Signature

interface PopoverTogglePayload extends TogglePayload {
readonly newState: "open" | "closed";
readonly oldState: "open" | "closed";
}

ScrollPayload

interface unstable
Since v4.2.0

The payload of scroll: the element's scroll offsets.

Signature

interface ScrollPayload {
readonly left: number;
readonly top: number;
}

SelectionPayload

interface unstable
Since v4.2.0

The payload of selectionchange on an input or textarea: the current caret or selection. The browser queues the event, so changes in one task can arrive as one.

Details

Offsets are in UTF-16 code units. They are null unless the target is a textarea or an input type with a selection, such as text or search: an email or number input reports none.

Signature

interface SelectionPayload {
readonly selectionEnd: number | null;
readonly selectionStart: number | null;
}

SubmitPayload

interface unstable
Since v4.2.0

The payload of submit: the form's fields.

Details

fields holds the first value of each named field, and entries every name and value in document order, for names used more than once. Files are left out. The browser's own submission is always prevented.

Signature

interface SubmitPayload {
readonly entries: readonly Array<readonly [string, string]>;
readonly fields: Readonly<Record<string, string>>;
}

TogglePayload

interface unstable
Since v4.2.0

The payload of toggle on a details or dialog: whether it's open now.

Signature

interface TogglePayload {
readonly open: boolean;
}

ValuePayload

interface unstable
Since v4.2.0

The payload of input and change on a textarea or select: the value the user left in the element, and how the edit was made.

Details

composing is true for an input sent while an input method composes text, which compositionend commits. inputType is the browser's name for the edit, such as "insertText", "deleteContentBackward" or "insertReplacementText" for autofill and spelling corrections. It is "" for a change, and for an input the browser names no edit for, such as choosing an option.

selectionStart and selectionEnd are the selection the edit left, as SelectionPayload describes. Read the caret here to keep it in step with value: selectionchange comes later, or not at all if the range didn't move.

Signature

interface ValuePayload extends SelectionPayload {
readonly composing: boolean;
readonly inputType: string;
readonly value: string;
}

Models

Element

unstable
Since v4.2.0

The builder of an HTML element that takes children: a VoidElement plus children.

Details

On h, a tag's root builder is also callable as shorthand for children, for an element with no attributes: h.span(title) is h.span.children(title). Either way the result is the builder, so more children and attributes can follow, and a second children adds after the first.

Signature

declare class Element<out Msg, out R = never, in out E = Record<string, unknown>, in out Node = unknown, out Tag extends string = string> extends VoidElement<Msg, R, E, Node, Tag> {
constructor<out Msg, out R = never, in out E = Record<string, unknown>, in out Node = unknown, out Tag extends string = string>(tag: string);
readonly "~With"?: Element<Msg, unknown, E, Node, Tag>;
children<This, C extends readonly Array<Input<Msg, unknown>>>(this: This, ...inputs: C): WithRequirements<This, Requirements<C[number]>>;
}

FocusOptions

interface unstable
Since v4.2.0

The options of focus.

Signature

interface FocusOptions {
readonly preventScroll?: boolean;
}

Rect

interface unstable
Since v4.2.0

An element's box, from measure, in CSS pixels relative to the viewport.

Signature

interface Rect {
readonly bottom: number;
readonly height: number;
readonly left: number;
readonly right: number;
readonly top: number;
readonly width: number;
readonly x: number;
readonly y: number;
}

ScrollOptions

interface unstable
Since v4.2.0

The options of scrollIntoView.

Signature

interface ScrollOptions {
readonly behavior?: "auto" | "instant" | "smooth";
readonly block?: "start" | "end" | "center" | "nearest";
readonly inline?: "start" | "end" | "center" | "nearest";
}

SelectOptions

interface unstable
Since v4.2.0

The options of select: the range to select, in UTF-16 code units. end defaults to start, which places the caret there.

Signature

interface SelectOptions {
readonly end?: number;
readonly start: number;
}

ValueNode

type unstable
Since v4.2.0

The nodes whose value is controlled.

Signature

type ValueNode = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement

VoidElement

unstable
Since v4.2.0

A builder without children, such as h.input or h.textarea. Extends the core builder with typed events, controlled properties, drag and drop, and attribute helpers. Element adds children.

Details

Events are the tag's events, Node the DOM element it renders to, which types ref and onMount, and Tag the tag, which a part of a headless component checks. Every method returns a copy. A builder is itself a valid child or view, so h.input.value(draft) needs no terminal call.

Signature

declare class VoidElement<out Msg, out R = never, in out E = Record<string, unknown>, in out Node = unknown, out Tag extends string = string> extends ElementBuilder<Msg, R, E, Node, Tag> {
constructor<out Msg, out R = never, in out E = Record<string, unknown>, in out Node = unknown, out Tag extends string = string>(tag: string);
readonly "~With"?: VoidElement<Msg, unknown, E, Node, Tag>;
checked(this: VoidElement<Msg, R, E, HTMLInputElement>, checked: boolean): this;
class(...tokens: readonly Array<ClassToken>): this;
disabled(disabled: boolean): this;
draggable(data: Readonly<Record<string, string>>, options?: {
readonly effectAllowed?: EffectAllowed;
}): this;
dropTarget(options: Omit<DropTargetOptions, "preventDefault">): this;
id(id: string): this;
modal<N extends HTMLDialogElement>(this: VoidElement<Msg, R, E, N>, modal: boolean): this;
on<K extends string>(event: K & keyof E, handler: Handler<Msg, E[K & keyof E]>, options?: EventOptionsOf<K>): this;
open<N extends HTMLDetailsElement | HTMLDialogElement>(this: VoidElement<Msg, R, E, N>, open: boolean): this;
popover(mode: PopoverMode, open: boolean): this;
selected(this: VoidElement<Msg, R, E, HTMLOptionElement>, selected: boolean): this;
style(style: Style): this;
value<N extends ValueNode>(this: VoidElement<Msg, R, E, N>, value: string): this;
}

Refs

ref

unstable
Since v4.2.0

Declares a ref to an element of tag tag, HTML or SVG. Attaching it to another tag doesn't compile. List rows use Row.at(id).

Signature

declare function ref<K extends "symbol" | "filter" | "circle" | "line" | "pattern" | "text" | "image" | "path" | "stop" | "use" | "clipPath" | "marker" | "mask" | "svg" | "g" | "ellipse" | "polyline" | "polygon" | "rect" | "tspan" | "textPath" | "defs" | "linearGradient" | "radialGradient" | "foreignObject" | keyof HTMLElementTagNameMap>(name: string, _tag: K): Ref<HTMLElementTagNameMap & Pick<SVGElementTagNameMap, "symbol" | "filter" | "circle" | "line" | "pattern" | "text" | "image" | "path" | "stop" | "use" | "clipPath" | "marker" | "mask" | "svg" | "g" | "ellipse" | "polyline" | "polygon" | "rect" | "tspan" | "textPath" | "defs" | "linearGradient" | "radialGradient" | "foreignObject">[K]>

Services

Host

unstable
Since v4.2.0

The HTML host marker: a host Layer that can show HTML elements provides it.

Details

mount requires it for an HTML root, so mounting one on another host is a type error. It's a framework service, so a Command may use it without it appearing in a component's requirements. It holds the element operations the ref Commands use, which a test on TestHost fakes with Layer.succeed(Html.Host, ...). showPicker returns whether the browser opened the picker.

Signature

declare class Host extends Shape<"effect/ui/html/Html/Host", {
readonly blur: (element: Element) => void;
readonly focus: (element: Element, options: FocusOptions) => void;
readonly measure: (element: Element) => Rect;
readonly requestSubmit: (element: Element) => boolean;
readonly scrollIntoView: (element: Element, options: ScrollOptions) => void;
readonly select: (element: Element, options?: SelectOptions) => void;
readonly showPicker: (element: Element) => boolean;
}, this> {
constructor(_: never);
}

Svg

SvgAttribute

type unstable
Since v4.2.0

Attribute names accepted by an SVG tag's attr and attrs: global and presentation attributes, plus tag-specific names such as d on path. Names are case-sensitive: use viewBox, not viewbox. For an unlisted name, pass a Record<string, string> to attrs, or use h.el(tag).

Signature

type SvgAttribute<Tag extends SvgTag> = SvgGlobalAttribute | SvgPresentationAttribute | SvgOwnAttributes[Tag]

SvgElement

interface unstable
Since v4.2.0

An SVG builder with id, class, style and attribute names checked by tag. HTML-only helpers such as value and disabled are excluded. Root builders on h are callable as shorthand for children.

Details

Node types the DOM element for ref and onMount; Tag selects the attribute names. See the module example for an icon.

Signature

interface SvgElement<Msg, R = never, Node = unknown, Tag extends SvgTag = SvgTag> extends ContainerBuilder<Msg, R, SvgEvents, Node, Tag> {
readonly "~With"?: SvgElement<Msg, unknown, Node, Tag>;
attr<Name extends string>(name: Name extends SvgAttribute<Tag> ? Name : SvgAttribute<Tag>, value: AttributeValue<Name>): this;
attrs<A extends AttributeValues<A>>(attributes: A & string extends keyof A ? unknown : { [K in string | number | symbol]: never }): this;
class(...tokens: readonly Array<ClassToken>): this;
id(id: string): this;
on<K extends string>(event: K & "focus" | "pointerdown" | "pointermove" | "pointerup" | "click" | "dblclick" | "contextmenu" | "mousedown" | "mouseup" | "pointercancel" | "pointerenter" | "pointerleave" | "keydown" | "keyup" | "blur" | "focusin" | "focusout", handler: Handler<Msg, SvgEvents[K & "focus" | "pointerdown" | "pointermove" | "pointerup" | "click" | "dblclick" | "contextmenu" | "mousedown" | "mouseup" | "pointercancel" | "pointerenter" | "pointerleave" | "keydown" | "keyup" | "blur" | "focusin" | "focusout"]>, options?: EventOptionsOf<K>): this;
style(style: Style): this;
}

SvgEvents

type unstable
Since v4.2.0

Pointer, mouse, keyboard and focus events supported by SVG builders.

Signature

type SvgEvents = Pick<Events, "click" | "dblclick" | "contextmenu" | "mousedown" | "mouseup" | "pointerdown" | "pointermove" | "pointerup" | "pointercancel" | "pointerenter" | "pointerleave" | "keydown" | "keyup" | "focus" | "blur" | "focusin" | "focusout">

SvgTag

type unstable
Since v4.2.0

An SVG tag.

Signature

type SvgTag = typeof svgTags[number]

svgTags

unstable
Since v4.2.0

Tags with named builders on h that render in the SVG namespace.

Signature

declare const svgTags: readonly ["svg", "g", "path", "circle", "ellipse", "line", "polyline", "polygon", "rect", "text", "tspan", "textPath", "defs", "use", "symbol", "clipPath", "mask", "pattern", "marker", "linearGradient", "radialGradient", "stop", "filter", "image", "foreignObject"]

Utility Types

H

type unstable
Since v4.2.0

The view helper for reusable pure HTML view functions, without a component definition.

Details

A shared view function takes the message as a type parameter, <M>(h: Html.H<M>, ...), whether or not it sends a message. Html.H<never> only accepts the h of a component with message: Schema.Never.

Props remain unknown and component-specific queries are not included. Use Component.Helper<D> instead when a function needs a definition's props, queries or custom elements.

Signature

type H<Msg> = View.WithTags<Msg, unknown, Elements>

Example A reusable button

import { Html } from "effect/ui/html"
import { Schema } from "effect"
const Button = <Msg>(h: Html.H<Msg>, label: string, message: Msg) =>
h.button.on("click", message).children(label)
export const Counter = Html.component({
name: "Counter",
model: Schema.Number,
message: Schema.Literal("ClickedIncrement")
}).make({
init: () => 0,
update: ($) => $.model + 1,
view: (h, count) => Button(h, String(count), "ClickedIncrement")
})

Vocabulary

ContainerTag

type unstable
Since v4.2.0

A tag that takes children.

Signature

type ContainerTag = typeof containerTags[number]
Since v4.2.0

The tags that take children.

Signature

declare const containerTags: readonly ["a", "abbr", "address", "article", "aside", "audio", "b", "bdi", "bdo", "blockquote", "button", "canvas", "caption", "cite", "code", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "i", "iframe", "ins", "kbd", "label", "legend", "li", "main", "mark", "menu", "meter", "nav", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "slot", "small", "span", "strong", "sub", "summary", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "time", "tr", "u", "ul", "var", "video"]

Elements

unstable
Since v4.2.0

Phantom: carries Elements on the module, so the module namespace is a View.Vocabulary<Elements>. It's undefined at runtime.

Signature

declare const Elements: Elements | undefined

Elements

interface unstable
Since v4.2.0

The type-level HTML vocabulary.

Signature

interface Elements extends Elements {
readonly Head: Entry;
readonly HeadValue: HtmlHead;
readonly Host: Host;
readonly Tags: Tags<unknown>;
}

name

unstable
Since v4.2.0

The vocabulary's name, which a host lists to show it.

Signature

declare const name: "html"

tags

unstable
Since v4.2.0

The root element builders installed on h, one per tag, shared by every render: a callable View.shorthand builder for a tag that takes children, SVG tags included, and a VoidElement for a void tag.

Signature

declare const tags: Readonly<Record<string, VoidElement<any, any, any, any>>>

Tags

type unstable
Since v4.2.0

The element names the vocabulary adds to h, bound to a component's message type. Document-level tags (html, head, body, title, meta, link, base, script, style) aren't here: the document head is managed through a component's head, with HtmlHead for its HTML entries.

Details

The SVG tags are here too, as SvgElement builders, with SVG's text as svgText.

Signature

type Tags<Msg> = { [K in ContainerTag]: View.Shorthand<Element<Msg, never, EventsOf<K>, HTMLElementTagNameMap[K], K>> } & { [K in VoidTag]: VoidElement<Msg, never, EventsOf<K>, HTMLElementTagNameMap[K], K> } & { [K in SvgTag]: View.Shorthand<SvgElement<Msg, never, SVGElementTagNameMap[K], K>> }

vocabulary

unstable
Since v4.2.0

The vocabulary alone: its name and its tags. Html.component passes it to Component.define.

When to use

Use to replace the module wherever elements is written by hand. A bundler keeps every export of a module that is passed as a value, such as Host, classNames and ref. With Html.vocabulary a bundle holds only the exports the app names.

Signature

declare const vocabulary: View.Vocabulary<Elements>

VoidTag

type unstable
Since v4.2.0

A tag that takes no children.

Signature

type VoidTag = typeof voidTags[number]

voidTags

unstable
Since v4.2.0

Tags whose builders take no children, including textarea. Set textarea content with .value(...); it is not an HTML void element.

Signature

declare const voidTags: readonly ["br", "col", "hr", "img", "input", "source", "textarea", "track", "wbr"]