Skip to content
// EFFECT DAYS 2026

Combobox unstable

An input that filters a list of options as the user types, and picks one or more of them.

Details

Combobox is headless: it owns the keyboard and pointer behaviour, the filtering, focus, placement, the data attributes and the form inputs, and the consumer draws the markup. The consumer owns whether the popup is open, what's selected and the input's text, passes them as open, value and inputValue, and stores what the RequestedOpen, RequestedClose, Picked and RequestedInputValue events ask for. Values are strings, and items lists every option with its label. The combobox filters them and hands back combobox.items, the ones to draw.

Anatomy:

Part Element
inputGroup <div> around the input and its buttons, the anchor
input <input>, the combobox
trigger <button> that toggles the popup
icon <span> inside the trigger
clear <button> that clears the text and the value
chips <div> around the chips and the input, with multiple
chip <div>, one per selected value
chipRemove <button> inside a chip
label <div> that names the input, the list and the popup
value <span> inside the trigger, with inputInPopup
backdrop <div>, a manual popover under the positioner
positioner <div>, a manual popover placed by the combobox
popup <div> inside the positioner
arrow <div> inside the popup
list <div> around the items
row <div> around a row of items, with grid
item <div>, one per drawn value, inside the list
itemIndicator <span> inside an item, shown while it's selected
group <div> around items
groupLabel <div> inside a group
separator <div> between items
empty <div>, its children drawn while no item matches
status <div>, a live region for a message such as a count
finalFocus any focusable element, focused on close

Each part takes the consumer's builder and returns it with the part applied, and the consumer adds the children. item, itemIndicator, chip and chipRemove take an options object, { element, value }, and group and groupLabel take { element, group }, where group is the group of the items inside. clear takes { element }. item and chip key their element with the value. clear and itemIndicator return undefined while they're hidden; a keepMounted field keeps them drawn. empty drops its children while the list has items, so the live region stays in the page.

Draw combobox.items, not items: it's the filtered list, which keeps its contents while the popup animates out. combobox.groups splits it by each item's group, dropping groups with nothing left, and each group's rows splits it again by row, for grid. Every value drawn with item has to be in items or filteredItems.

Focus stays in the input: the highlighted item is named by aria-activedescendant, and presses on the trigger, the clear button, the chips and the items don't take focus. In a Field, draw it as combobox.input(field.control(h.input)) and name it with field.label.

With inputInPopup, the trigger is the combobox and shows the selected label in value, the popup is a dialog, and opening moves focus to the input inside it. Name the trigger with label.

With inline, the list is drawn without a popup, as in a command palette: it's always expanded, and the arrow keys move through it while open is false.

The positioner is a manual popover, so it renders in the top layer and needs no portal. The browser gives a popover a border, padding, a background and overflow: auto, so reset those on the positioner and the backdrop and style the popup instead.

With topLayer: false, the backdrop and the positioner render in place as ordinary elements, hidden while closed, and the popup is placed and clipped inside its containing block, as Positioning describes. The backdrop covers that block, and the combobox is never modal.

CSS variables:

Set on the positioner:

  • --anchor-width, --anchor-height: the anchor's size
  • --available-width, --available-height: the space between the anchor and the edge of the collision boundary, for a max-height

Set on the popup: --transform-origin, the point the popup grows from.

Data attributes:

Each present with an empty value or absent, except data-side, data-align, data-popup-side and data-orientation, which hold a value:

  • input: data-popup-open, data-pressed, data-popup-side, data-list-empty, data-disabled, data-readonly, data-required
  • inputGroup: as on the input, without data-required, and with data-placeholder
  • trigger: as on the input, and data-placeholder
  • icon: data-popup-open
  • clear: data-popup-open, data-disabled, data-visible
  • value: data-placeholder
  • chip, chipRemove: data-disabled
  • backdrop: data-open / data-closed, data-starting-style, data-ending-style
  • positioner: as on the backdrop, and data-side, data-align, data-anchor-hidden, data-empty
  • popup: as on the positioner
  • arrow: as on the backdrop, and data-side, data-align, data-uncentered
  • list: data-empty
  • item: data-selected, data-highlighted, data-disabled
  • separator: data-orientation

Keyboard:

In the input, ArrowDown and ArrowUp open the popup on the selected item, or on the first or, for ArrowUp, the last item, and then move the highlight. Past either end the highlight leaves the list, and the next press wraps around; with loopFocus: false it stops at the ends. Enter picks the highlighted item, and with nothing highlighted it closes the popup on its keyup, leaving the keydown to submit a form. Space picks the highlighted item while the input is empty. Escape closes the popup, and on a closed combobox clears the text and the value. Typing opens the popup. Keys pressed while an IME composes text are left alone.

With grid, ArrowLeft and ArrowRight move between the items of a row once one is highlighted. With chips, ArrowLeft with the caret at the start of the input moves focus to the last chip, and Backspace in an empty input removes the last value. On a chip, ArrowLeft and ArrowRight move between chips and back to the input, Backspace and Delete remove it, and Enter, Space, a letter, ArrowDown and ArrowUp return to the input, the arrows opening the popup. The horizontal arrows follow dir or, without it, the nearest DirectionProvider above the combobox or, without one, the CSS direction of the chips for the chip keys, and of the popup or an inline list for the item keys.

With inputInPopup, ArrowDown and ArrowUp on the trigger open the popup, and typing a letter on the closed trigger selects the next matching item without opening.

Form:

With name, required or autoComplete, the input, or the trigger with inputInPopup, is wrapped in a display: contents span that holds a visually hidden input, so required blocks a form's submission, the browser can autofill it, and the value is submitted. Autofill picks the item whose value, then whose label, matches. A multiple combobox submits one hidden input per value. An empty string counts as no value.

Limits:

Props can't hold functions, so filter names a matcher and a consumer with its own filter passes the result as filteredItems, or sets filter: "none" and filters the items it passes, as for results fetched while typing. makeComboboxFilter gives the combobox's matchers to a consumer's own filter. There are no default* props or refs, no portal, and items are { value, label } rather than any object.

Example A fruit picker in a field, with the open state, the value and the text in the consumer's Model

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Combobox, Field } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const fruits = [
{ value: "apple", label: "Apple" },
{ value: "banana", label: "Banana" },
{ value: "grape", label: "Grape" }
]
const PickerMessage = UiSchema.TaggedEnum({
RequestedOpenFruit: {},
RequestedCloseFruit: {},
PickedFruit: { fruit: Schema.NullOr(Schema.String) },
RequestedInputValueFruit: { text: Schema.String }
})
const Picker = Html.component({
name: "Picker",
model: Schema.Struct({ open: Schema.Boolean, fruit: Schema.NullOr(Schema.String), text: Schema.String }),
message: PickerMessage
}).make({
init: () => ({ open: false, fruit: "banana", text: "Banana" }),
update: {
RequestedOpenFruit: ($) => $.evolve({ open: true }),
RequestedCloseFruit: ($) => $.evolve({ open: false }),
PickedFruit: ($, { fruit }) => $.evolve({ fruit }),
RequestedInputValueFruit: ($, { text }) => $.evolve({ text })
},
view: (h, model) =>
Field(h, {
props: { filled: model.fruit !== null },
view: (field) =>
Combobox(h, {
props: {
open: model.open,
value: model.fruit,
inputValue: model.text,
items: fruits,
name: "fruit",
disabled: field.disabled
},
onEmit: {
RequestedOpen: () => PickerMessage.RequestedOpenFruit(),
RequestedClose: () => PickerMessage.RequestedCloseFruit(),
Picked: ({ value }) => PickerMessage.PickedFruit({ fruit: typeof value === "string" ? value : null }),
RequestedInputValue: ({ inputValue }) => PickerMessage.RequestedInputValueFruit({ text: inputValue }),
Highlighted: () => undefined,
Settled: () => undefined
},
view: (combobox) =>
field.root(h.div).children(
field.label(h.label).children("Fruit"),
combobox.inputGroup(h.div).children(
combobox.input(field.control(h.input)),
combobox.clear({ element: h.button })?.children("ร—"),
combobox.trigger(h.button).children(combobox.icon(h.span).children("โ–พ"))
),
combobox.positioner(h.div).children(
combobox.popup(h.div).children(
combobox.empty(h.div).children("No fruit found"),
combobox.list(h.div).children(
combobox.items.map(({ label, value }) =>
combobox.item({ element: h.div, value }).children(
label,
combobox.itemIndicator({ element: h.span, value })?.children("โœ“")
)
)
)
)
)
)
})
})
})
// The input is a combobox that shows the selected fruit.
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Picker, {}))
if (!/<input[^>]* role="combobox"/.test(html) || !/<input[^>]* value="Banana"/.test(html)) {
throw new Error("the input doesn't show the fruit")
}
22 exports Since v4.2.0 Source

Components

Combobox

unstable
Since v4.2.0

A combobox: an input that filters a list of options as the user types.

Details

The parts also return plain values for markup that depends on them: open, mounted (the popup shows, through its exit transition), transitionStatus, inline, selected (the value prop, or null), selectedItems (the selected values with their labels, for chips), placeholder (nothing is selected), disabled, readOnly, required, multiple, side and align (where the popup ended up), highlighted (the value of the highlighted item), openMethod, which is null once the popup closes, items (the filtered items to draw), groups and listEmpty.

Each part's attributes win over the ones the consumer set on the builder before the part, including the ones a state leaves absent. Besides the ones under Data attributes in the module docs, they are:

  • input: role="combobox", aria-expanded, aria-haspopup ("grid" with grid, otherwise "listbox"), aria-controls and aria-activedescendant while the list can be navigated, aria-autocomplete, aria-readonly, aria-required, readonly, disabled, value, and autocomplete="off", spellcheck, autocorrect and autocapitalize. Its id is the one already on the builder, as from field.control. Otherwise it's the id prop, or a generated one with inputInPopup.
  • trigger: type="button", aria-expanded, aria-haspopup ("dialog" with inputInPopup, else as on the input), aria-controls while open, disabled, and tabindex="-1" and a fallback aria-label="Open popup" without inputInPopup. With inputInPopup it takes focus and is a combobox as well as the input: role="combobox", aria-required, aria-readonly, an id, the one on the builder or else the id prop, and aria-labelledby pointing at label when the builder has none.
  • inputGroup: role="group"
  • clear, chipRemove: type="button", tabindex="-1", disabled, and a fallback aria-label="Clear" or aria-label="Remove". It's left out when the builder has a name or text children, and is a title when a child is a component, so text the component renders still wins
  • chips: role="toolbar", and a visually hidden role="status" that says which chip value lost last
  • chip: tabindex="-1", and aria-keyshortcuts="Backspace Delete" unless disabled or readOnly
  • label: id
  • backdrop, positioner: role="presentation" and popover="manual"
  • popup: id, tabindex="-1" and role="presentation", or with inputInPopup role="dialog", aria-modal and aria-labelledby pointing at label
  • list: id, role="listbox", or "grid" with grid, tabindex="-1", aria-multiselectable, aria-readonly, and aria-labelledby pointing at label
  • row: role="row"
  • item: id, role="option", or "gridcell" with grid, aria-selected, aria-disabled
  • group: role="group", or "rowgroup" with grid, and aria-labelledby pointing at its groupLabel
  • groupLabel: id and aria-hidden="true"
  • icon, arrow, itemIndicator: aria-hidden="true", and id on the arrow
  • separator: role="separator", aria-orientation="horizontal"
  • empty, status: role="status", aria-live="polite", aria-atomic="true"

A part adds the ids it lists in aria-controls, and a group's aria-labelledby, to the consumer's. Other names are fallbacks, left out when the builder has an aria-label or aria-labelledby. Except with inline, or with inputInPopup and not modal, the positioner also holds a visually hidden Dismiss button for screen readers.

The parts handle these events on a layer of their own, so the consumer's handlers for them still run:

  • input: input, compositionend, keydown, keyup and mousedown, and focusin and focusout with inline
  • trigger: mousedown, mouseup, click and keydown
  • inputGroup, chips: mousedown, and the chips' keydown through the mount on chips
  • clear, chipRemove: mousedown and click
  • label: click
  • item: pointerenter, pointerleave, mousedown, mouseup and click

They cancel the keys they handle, and the mousedown on the input group, the chips, the clear and remove buttons, the trigger without inputInPopup and the items, so focus stays in the input. The positioner's mount places the popup and listens for presses and focus outside it. With inputInPopup, it moves focus into the popup, and if it opens during mousedown, it cancels the default action to keep focus there. The mounts on the positioner, the chips and an inline list also read their CSS direction.

It emits RequestedOpen, RequestedClose, Picked, RequestedInputValue, Highlighted and Settled.

History restore saves nothing of it: after Back, forward or a reload it starts from init.

Signature

declare const Combobox: Headless<{
readonly align?: "start" | "end" | "center";
readonly alignOffset?: number;
readonly anchor?: string | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly arrowPadding?: number;
readonly autoComplete?: string;
readonly autoHighlight?: boolean;
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly collisionBoundary?: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly collisionPadding?: number | {
readonly bottom?: number;
readonly left?: number;
readonly right?: number;
readonly top?: number;
};
readonly dir?: "ltr" | "rtl";
readonly disableAnchorTracking?: boolean;
readonly disabled?: boolean;
readonly dismissLabel?: string;
readonly filter?: "endsWith" | "startsWith" | "none" | "contains";
readonly filteredItems?: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: string;
}>;
readonly finalFocus?: boolean;
readonly form?: string;
readonly grid?: boolean;
readonly highlightItemOnHover?: boolean;
readonly holdExit?: boolean;
readonly id?: string;
readonly inline?: boolean;
readonly inputInPopup?: boolean;
readonly inputValue: string;
readonly items: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: string;
}>;
readonly limit?: number;
readonly locale?: string;
readonly loopFocus?: boolean;
readonly modal?: boolean;
readonly multiple?: boolean;
readonly name?: string;
readonly open: boolean;
readonly openOnInputClick?: boolean;
readonly placeholder?: string;
readonly positionMethod?: "fixed" | "absolute";
readonly readOnly?: boolean;
readonly removedLabel?: string;
readonly required?: boolean;
readonly side?: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset?: number;
readonly sticky?: boolean;
readonly topLayer?: boolean;
readonly value?: string | readonly Array<string> | null;
readonly virtualized?: boolean;
}, {
readonly _tag: "Settled";
readonly open: boolean;
} | {
readonly _tag: "RequestedOpen";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
} | {
readonly _tag: "RequestedClose";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
} | {
readonly _tag: "Highlighted";
readonly index: number;
readonly reason: "none" | "pointer" | "keyboard";
readonly value: string | null;
} | {
readonly _tag: "Picked";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
readonly value: string | readonly Array<string> | null;
} | {
readonly _tag: "RequestedInputValue";
readonly inputValue: string;
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
}, {
align: "start" | "end" | "center";
arrow: Part<"div", [], never>;
backdrop: Part<"div", [], never>;
chip: <B extends Keyed<"div">>(__namedParameters: {
readonly element: B;
readonly value: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [value: string], never>, "~R">;
chipRemove: <B extends PartTarget<"button">>(__namedParameters: {
readonly element: B;
readonly value: string;
}) => ReturnType<B["attr"]> & Pick<Part<"button", [value: string], never>, "~R">;
chips: Part<"div", [], never>;
clear: <B extends PartTarget<"button">>(__namedParameters: {
readonly element: B;
readonly keepMounted?: boolean;
}) => ReturnType<B["attr"]> | undefined & Pick<Part<"button", [], never>, "~R">;
disabled: boolean;
empty: Part<"div", [], never>;
finalFocus: Part<string, [], never>;
group: <B extends PartTarget<"div">>(__namedParameters: {
readonly element: B;
readonly group: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [group: string], never>, "~R">;
groupLabel: <B extends PartTarget<"div">>(__namedParameters: {
readonly element: B;
readonly group: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [group: string], never>, "~R">;
groups: readonly Array<Group<string>>;
highlighted: string | null;
icon: Part<"span", [], never>;
inline: boolean;
input: Part<"input", [], never>;
inputGroup: Part<"div", [], never>;
item: <B extends Keyed<"div">>(__namedParameters: {
readonly element: B;
readonly value: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [value: string], never>, "~R">;
itemIndicator: <B extends PartTarget<"span">>(__namedParameters: {
readonly element: B;
readonly keepMounted?: boolean;
readonly value: string;
}) => ReturnType<B["attr"]> | undefined & Pick<Part<"span", [], never>, "~R">;
items: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: string;
}>;
label: Part<"div", [], never>;
list: Part<"div", [], never>;
listEmpty: boolean;
mounted: boolean;
multiple: boolean;
open: boolean;
openMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
placeholder: boolean;
popup: Part<"div", [], never>;
positioner: Part<"div", [], never>;
readOnly: boolean;
required: boolean;
row: Part<"div", [], never>;
selected: string | readonly Array<string> | null;
selectedItems: Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: string;
}>;
separator: Part<"div", [], never>;
side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
status: Part<"div", [], never>;
transitionStatus: TransitionStatus;
trigger: Part<"button", [], never>;
value: Part<"span", [], never>;
}, never, never, never, never, never, never, {
readonly active: string | null;
readonly activeByKey: boolean;
readonly autoFirst: boolean;
readonly chipsRtl: boolean;
readonly closeMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
readonly closeQuery: string | null;
readonly completion: {
readonly from: string;
readonly label: string;
} | null;
readonly focusLeft: boolean;
readonly mounted: boolean;
readonly openMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
readonly placement: {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
} | null;
readonly pressedItem: string | null;
readonly pressing: boolean;
readonly queryChanged: boolean;
readonly removing: {
readonly label: string;
readonly value: string;
} | null;
readonly rtl: boolean;
readonly saved: string | null;
readonly started: boolean;
readonly typeahead: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
};
}, {
readonly _tag: "RenderedFirstFrame";
} | {
readonly _tag: "FocusedOutside";
} | {
readonly _tag: "ClickedTrigger";
readonly pointerType: string;
} | {
readonly _tag: "FinishedTransition";
readonly open: boolean;
} | {
readonly _tag: "PressedOutside";
readonly pointerType: string;
} | {
readonly _tag: "PressedInput";
readonly pointerType: string;
} | {
readonly _tag: "PressedGroup";
readonly pointerType: string;
} | {
readonly _tag: "ChangedInput";
readonly composing: boolean;
readonly inputType: string;
readonly value: string;
} | {
readonly _tag: "PressedInputKey";
readonly chips: boolean;
readonly key: string;
} | {
readonly _tag: "ReleasedInputKey";
readonly key: string;
} | {
readonly _tag: "FocusedInput";
} | {
readonly _tag: "BlurredInput";
} | {
readonly _tag: "PressedTrigger";
readonly pointerType: string;
} | {
readonly _tag: "ReleasedTrigger";
} | {
readonly _tag: "PressedTriggerKey";
readonly key: string;
} | {
readonly _tag: "ClickedLabel";
} | {
readonly _tag: "FocusedFormInput";
} | {
readonly _tag: "Autofilled";
readonly value: string;
} | {
readonly _tag: "PressedClear";
} | {
readonly _tag: "RequestedChipRemoval";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
readonly value: string;
} | {
readonly _tag: "PressedChipArrow";
readonly key: string;
} | {
readonly _tag: "EnteredItem";
readonly value: string;
} | {
readonly _tag: "LeftItem";
} | {
readonly _tag: "PressedItem";
readonly value: string;
} | {
readonly _tag: "ReleasedItem";
readonly button: number;
readonly value: string;
} | {
readonly _tag: "ClickedItem";
readonly pointerType: string;
readonly value: string;
} | {
readonly _tag: "PressedDismiss";
} | {
readonly _tag: "CompletedWaitBeforeResetTyping";
} | {
readonly _tag: "ShowedPopup";
} | {
readonly _tag: "ChangedPlacement";
readonly placement: {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
};
} | {
readonly _tag: "ReleasedPointer";
readonly outside: boolean;
} | {
readonly _tag: "FoundDirection";
readonly rtl: boolean;
} | {
readonly _tag: "FoundChipsDirection";
readonly rtl: boolean;
}, QueryEntries<{}, {}>>
Since v4.2.0

Creates a combobox whose selected values, items, value-taking parts and Picked and Highlighted events use the supplied string-valued schema. Input text remains a string. Selections come from items or value; autofill selects only a matching item.

Details

The schema must encode to a string. Create the component once at module level: each call creates a new component. The existing Combobox export uses Schema.String.

Signature

declare function makeCombobox<V extends string>(options: {
readonly value: Codec<V, string>;
}): Headless<{
readonly align?: "start" | "end" | "center";
readonly alignOffset?: number;
readonly anchor?: string | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
};
readonly arrowPadding?: number;
readonly autoComplete?: string;
readonly autoHighlight?: boolean;
readonly collisionAvoidance?: {
readonly align?: "shift" | "none" | "flip";
readonly fallbackAxisSide?: "start" | "none" | "end";
readonly side?: "shift" | "none" | "flip";
};
readonly collisionBoundary?: "clipping-ancestors" | {
readonly height: number;
readonly width: number;
readonly x: number;
readonly y: number;
} | {
readonly id: string;
};
readonly collisionPadding?: number | {
readonly bottom?: number;
readonly left?: number;
readonly right?: number;
readonly top?: number;
};
readonly dir?: "ltr" | "rtl";
readonly disableAnchorTracking?: boolean;
readonly disabled?: boolean;
readonly dismissLabel?: string;
readonly filter?: "endsWith" | "startsWith" | "none" | "contains";
readonly filteredItems?: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: V;
}>;
readonly finalFocus?: boolean;
readonly form?: string;
readonly grid?: boolean;
readonly highlightItemOnHover?: boolean;
readonly holdExit?: boolean;
readonly id?: string;
readonly inline?: boolean;
readonly inputInPopup?: boolean;
readonly inputValue: string;
readonly items: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: V;
}>;
readonly limit?: number;
readonly locale?: string;
readonly loopFocus?: boolean;
readonly modal?: boolean;
readonly multiple?: boolean;
readonly name?: string;
readonly open: boolean;
readonly openOnInputClick?: boolean;
readonly placeholder?: string;
readonly positionMethod?: "fixed" | "absolute";
readonly readOnly?: boolean;
readonly removedLabel?: string;
readonly required?: boolean;
readonly side?: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
readonly sideOffset?: number;
readonly sticky?: boolean;
readonly topLayer?: boolean;
readonly value?: V | readonly Array<V> | null;
readonly virtualized?: boolean;
}, {
readonly _tag: "Settled";
readonly open: boolean;
} | {
readonly _tag: "RequestedOpen";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
} | {
readonly _tag: "RequestedClose";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
} | {
readonly _tag: "Highlighted";
readonly index: number;
readonly reason: "none" | "pointer" | "keyboard";
readonly value: V | null;
} | {
readonly _tag: "Picked";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
readonly value: V | readonly Array<V> | null;
} | {
readonly _tag: "RequestedInputValue";
readonly inputValue: string;
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
}, {
align: "start" | "end" | "center";
arrow: Part<"div", [], never>;
backdrop: Part<"div", [], never>;
chip: <B extends Keyed<"div">>(__namedParameters: {
readonly element: B;
readonly value: V;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [value: V], never>, "~R">;
chipRemove: <B extends PartTarget<"button">>(__namedParameters: {
readonly element: B;
readonly value: V;
}) => ReturnType<B["attr"]> & Pick<Part<"button", [value: V], never>, "~R">;
chips: Part<"div", [], never>;
clear: <B extends PartTarget<"button">>(__namedParameters: {
readonly element: B;
readonly keepMounted?: boolean;
}) => ReturnType<B["attr"]> | undefined & Pick<Part<"button", [], never>, "~R">;
disabled: boolean;
empty: Part<"div", [], never>;
finalFocus: Part<string, [], never>;
group: <B extends PartTarget<"div">>(__namedParameters: {
readonly element: B;
readonly group: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [group: string], never>, "~R">;
groupLabel: <B extends PartTarget<"div">>(__namedParameters: {
readonly element: B;
readonly group: string;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [group: string], never>, "~R">;
groups: readonly Array<Group<V>>;
highlighted: V | null;
icon: Part<"span", [], never>;
inline: boolean;
input: Part<"input", [], never>;
inputGroup: Part<"div", [], never>;
item: <B extends Keyed<"div">>(__namedParameters: {
readonly element: B;
readonly value: V;
}) => ReturnType<B["attr"]> & Pick<Part<"div", [value: V], never>, "~R">;
itemIndicator: <B extends PartTarget<"span">>(__namedParameters: {
readonly element: B;
readonly keepMounted?: boolean;
readonly value: V;
}) => ReturnType<B["attr"]> | undefined & Pick<Part<"span", [], never>, "~R">;
items: readonly Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: V;
}>;
label: Part<"div", [], never>;
list: Part<"div", [], never>;
listEmpty: boolean;
mounted: boolean;
multiple: boolean;
open: boolean;
openMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
placeholder: boolean;
popup: Part<"div", [], never>;
positioner: Part<"div", [], never>;
readOnly: boolean;
required: boolean;
row: Part<"div", [], never>;
selected: V | readonly Array<V> | null;
selectedItems: Array<{
readonly disabled?: boolean;
readonly group?: string;
readonly label: string;
readonly row?: number;
value: V;
}>;
separator: Part<"div", [], never>;
side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
status: Part<"div", [], never>;
transitionStatus: TransitionStatus;
trigger: Part<"button", [], never>;
value: Part<"span", [], never>;
}, Exclude<PartRequirements<V>, FrameworkService>, never, never, never, never, never, {
readonly active: string | null;
readonly activeByKey: boolean;
readonly autoFirst: boolean;
readonly chipsRtl: boolean;
readonly closeMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
readonly closeQuery: string | null;
readonly completion: {
readonly from: string;
readonly label: string;
} | null;
readonly focusLeft: boolean;
readonly mounted: boolean;
readonly openMethod: "mouse" | "touch" | "pen" | "keyboard" | null;
readonly placement: {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
} | null;
readonly pressedItem: string | null;
readonly pressing: boolean;
readonly queryChanged: boolean;
readonly removing: {
readonly label: string;
readonly value: string;
} | null;
readonly rtl: boolean;
readonly saved: string | null;
readonly started: boolean;
readonly typeahead: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
};
}, {
readonly _tag: "RenderedFirstFrame";
} | {
readonly _tag: "FocusedOutside";
} | {
readonly _tag: "ClickedTrigger";
readonly pointerType: string;
} | {
readonly _tag: "FinishedTransition";
readonly open: boolean;
} | {
readonly _tag: "PressedOutside";
readonly pointerType: string;
} | {
readonly _tag: "PressedInput";
readonly pointerType: string;
} | {
readonly _tag: "PressedGroup";
readonly pointerType: string;
} | {
readonly _tag: "ChangedInput";
readonly composing: boolean;
readonly inputType: string;
readonly value: string;
} | {
readonly _tag: "PressedInputKey";
readonly chips: boolean;
readonly key: string;
} | {
readonly _tag: "ReleasedInputKey";
readonly key: string;
} | {
readonly _tag: "FocusedInput";
} | {
readonly _tag: "BlurredInput";
} | {
readonly _tag: "PressedTrigger";
readonly pointerType: string;
} | {
readonly _tag: "ReleasedTrigger";
} | {
readonly _tag: "PressedTriggerKey";
readonly key: string;
} | {
readonly _tag: "ClickedLabel";
} | {
readonly _tag: "FocusedFormInput";
} | {
readonly _tag: "Autofilled";
readonly value: string;
} | {
readonly _tag: "PressedClear";
} | {
readonly _tag: "RequestedChipRemoval";
readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "input-press" | "item-press" | "list-navigation" | "input-change" | "input-clear" | "clear-press" | "cancel-open" | "chip-remove-press";
readonly value: string;
} | {
readonly _tag: "PressedChipArrow";
readonly key: string;
} | {
readonly _tag: "EnteredItem";
readonly value: string;
} | {
readonly _tag: "LeftItem";
} | {
readonly _tag: "PressedItem";
readonly value: string;
} | {
readonly _tag: "ReleasedItem";
readonly button: number;
readonly value: string;
} | {
readonly _tag: "ClickedItem";
readonly pointerType: string;
readonly value: string;
} | {
readonly _tag: "PressedDismiss";
} | {
readonly _tag: "CompletedWaitBeforeResetTyping";
} | {
readonly _tag: "ShowedPopup";
} | {
readonly _tag: "ChangedPlacement";
readonly placement: {
readonly align: "start" | "end" | "center";
readonly anchorHidden: boolean;
readonly arrowUncentered: boolean;
readonly side: "left" | "right" | "top" | "bottom" | "inline-start" | "inline-end";
};
} | {
readonly _tag: "ReleasedPointer";
readonly outside: boolean;
} | {
readonly _tag: "FoundDirection";
readonly rtl: boolean;
} | {
readonly _tag: "FoundChipsDirection";
readonly rtl: boolean;
}, QueryEntries<{}, {}>>

Example A combobox typed by a literal union

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { makeCombobox } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const Fruit = Schema.Literals(["apple", "pear"])
const FruitCombobox = makeCombobox({ value: Fruit })
const items = [{ value: "apple", label: "Apple" }, { value: "pear", label: "Pear" }] as const
const Message = UiSchema.TaggedEnum({
PickedFruit: { fruit: Schema.NullOr(Fruit) },
Typed: { text: Schema.String }
})
const Picker = Html.component({
name: "Picker",
model: Schema.Struct({ fruit: Schema.NullOr(Fruit), text: Schema.String }),
message: Message
}).make({
init: () => ({ fruit: "pear" as const, text: "Pear" }),
update: {
PickedFruit: ($, { fruit }) => $.evolve({ fruit }),
Typed: ($, { text }) => $.evolve({ text })
},
view: (h, model) =>
FruitCombobox(h, {
props: { open: false, value: model.fruit, inputValue: model.text, items },
onEmit: {
// `value` is "apple" | "pear" | ReadonlyArray<"apple" | "pear"> | null
Picked: ({ value }) => Message.PickedFruit({ fruit: typeof value === "string" ? value : null }),
RequestedInputValue: ({ inputValue }) => Message.Typed({ text: inputValue }),
RequestedOpen: () => undefined,
RequestedClose: () => undefined,
Highlighted: () => undefined,
Settled: () => undefined
},
view: (combobox) => combobox.input(h.input.attr("aria-label", "Fruit"))
})
})
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Picker, {}))
if (!html.includes('value="Pear"')) throw new Error("the input doesn't show the label")

Constructors

Since v4.2.0

The ComboboxFilter for a locale, the runtime's when left out. It's cached, so calling it for each render is cheap.

Signature

declare function makeComboboxFilter(locale?: string): ComboboxFilter

Example Filtering items the consumer fetched

import { makeComboboxFilter } from "effect/ui/kit"
const filter = makeComboboxFilter("fr")
filter.startsWith("ร‰clair", "ecl") // true

Models

Since v4.2.0

Why a Combobox asks to open, close or change its value or its text.

Signature

type ComboboxChangeReason = typeof ComboboxChangeReason.Type

ComboboxEvents

type unstable
Since v4.2.0

What a Combobox emits.

Signature

type ComboboxEvents<V extends string = string> = ReturnType<typeof eventsSchema>["Type"]

ComboboxFilter

interface unstable
Since v4.2.0

The matchers a Combobox filters with, for a consumer's own filter.

Details

Each takes an item's text and the query, and ignores case, accents and punctuation. An empty query matches everything.

Signature

interface ComboboxFilter extends TextFilter {}

ComboboxFilterMode

type unstable
Since v4.2.0

How a Combobox matches its items against the text.

Signature

type ComboboxFilterMode = typeof ComboboxFilterMode.Type

ComboboxGroup

interface unstable
Since v4.2.0

A run of items to draw under one group label: the items whose group is key, in order, and the same items split into rows by their row.

Signature

interface ComboboxGroup<V extends string = string> extends Group<V> {}
Since v4.2.0

What moved the highlight.

Signature

type ComboboxHighlightReason = typeof ComboboxHighlightReason.Type

ComboboxInteraction

type unstable
Since v4.2.0

How the combobox was opened or closed.

Signature

type ComboboxInteraction = typeof ComboboxInteraction.Type

ComboboxItem

type unstable
Since v4.2.0

One option of a Combobox.

Signature

type ComboboxItem<V extends string = string> = Engine.Item<V>

ComboboxProps

type unstable
Since v4.2.0

The props of a Combobox.

Signature

type ComboboxProps<V extends string = string> = ReturnType<typeof propsSchema>["Type"]
Since v4.2.0

Where a combobox's popup is in its transitions: "starting" for the first frame after it opens, "ending" while it closes, null otherwise.

Signature

type ComboboxTransitionStatus = Engine.TransitionStatus

ComboboxValue

type unstable
Since v4.2.0

What a Combobox holds.

Signature

type ComboboxValue<V extends string = string> = ReturnType<typeof valueSchema>["Type"]

Schemas

Since v4.2.0

Why a Combobox asks to open, close or change its value or its text.

Details

  • "trigger-press": a press on the trigger
  • "input-press": a press on the input or the input group
  • "outside-press": a press outside the combobox and the popup, other than on a scrollbar
  • "item-press": an item was picked, with the pointer or the keyboard
  • "close-press": the visually hidden dismiss button in the popup, for screen readers
  • "escape-key": Escape in the input
  • "list-navigation": ArrowDown or ArrowUp opened the popup
  • "focus-out": focus left the combobox and the popup
  • "input-change": the user edited the input's text
  • "input-clear": the combobox cleared the text, or the user emptied it, which clears a single value
  • "clear-press": the clear button
  • "chip-remove-press": a chip's remove button
  • "cancel-open": the press that opened it was released away from the trigger and the popup
  • "none": anything else, such as typeahead on the trigger, autofill, Backspace removing a chip, or the selected label put back in the input

Signature

declare const ComboboxChangeReason: Literals<readonly ["trigger-press", "input-press", "outside-press", "item-press", "close-press", "escape-key", "list-navigation", "focus-out", "input-change", "input-clear", "clear-press", "cancel-open", "none", "chip-remove-press"]>
Since v4.2.0

What a Combobox emits.

Details

  • RequestedOpen: asks for open to be true.
  • RequestedClose: asks for open to be false.
  • Picked: asks for value to be value, the whole new selection.
  • RequestedInputValue: asks for inputValue to be inputValue. A single pick asks for the picked label, and after the popup closes the combobox asks for the selected label back, or for empty text with multiple or inputInPopup.
  • Highlighted: reports that the highlighted item changed, to value at index in combobox.items, or to none with null and -1. For a virtualized list to scroll to it.
  • Settled: reports that the popup's transitions ended, after it opened or closed.

Signature

declare const ComboboxEvents: TaggedEnum<{
Highlighted: TaggedStruct<"Highlighted", {
readonly index: Number;
readonly reason: Literals<readonly ["keyboard", "pointer", "none"]>;
readonly value: NullOr<String>;
}>;
Picked: TaggedStruct<"Picked", {
readonly reason: Literals<readonly ["trigger-press", "input-press", "outside-press", "item-press", "close-press", "escape-key", "list-navigation", "focus-out", "input-change", "input-clear", "clear-press", "cancel-open", "none", "chip-remove-press"]>;
readonly value: NullOr<Union<readonly [String, $Array<String>]>>;
}>;
RequestedClose: TaggedStruct<"RequestedClose", {
readonly reason: Literals<readonly ["trigger-press", "input-press", "outside-press", "item-press", "close-press", "escape-key", "list-navigation", "focus-out", "input-change", "input-clear", "clear-press", "cancel-open", "none", "chip-remove-press"]>;
}>;
RequestedInputValue: TaggedStruct<"RequestedInputValue", {
readonly inputValue: String;
readonly reason: Literals<readonly ["trigger-press", "input-press", "outside-press", "item-press", "close-press", "escape-key", "list-navigation", "focus-out", "input-change", "input-clear", "clear-press", "cancel-open", "none", "chip-remove-press"]>;
}>;
RequestedOpen: TaggedStruct<"RequestedOpen", {
readonly reason: Literals<readonly ["trigger-press", "input-press", "outside-press", "item-press", "close-press", "escape-key", "list-navigation", "focus-out", "input-change", "input-clear", "clear-press", "cancel-open", "none", "chip-remove-press"]>;
}>;
Settled: TaggedStruct<"Settled", {
readonly open: Boolean;
}>;
}>
Since v4.2.0

How a Combobox matches its items against the text.

Details

  • "contains": the label contains the text
  • "startsWith": the label starts with it
  • "endsWith": the label ends with it
  • "none": every item is drawn, for a consumer that filters items itself

Matching ignores case, accents and punctuation, in the locale.

Signature

declare const ComboboxFilterMode: Literals<readonly ["contains", "startsWith", "endsWith", "none"]>

What moved the highlight: "keyboard", "pointer", or "none" for the combobox itself, as when it opens or the list changes.

Signature

declare const ComboboxHighlightReason: Literals<readonly ["keyboard", "pointer", "none"]>
Since v4.2.0

How the combobox was opened or closed: "keyboard" for a key or a click from no pointer.

Signature

declare const ComboboxInteraction: Literals<readonly ["mouse", "touch", "pen", "keyboard"]>
Since v4.2.0

One option of a Combobox.

Details

  • value: what's selected and submitted. Unique among the items.
  • label: the text matched while filtering, put in the input when the item is picked, and shown in the value part.
  • disabled: the item can be highlighted but not picked.
  • group: the key of the group it's drawn in, for combobox.groups.
  • row: the row it's drawn in, for grid. Neighbouring items of a group with the same row share a row.

Signature

declare const ComboboxItem: Struct<{
readonly disabled: optional<Boolean>;
readonly group: optional<String>;
readonly label: String;
readonly row: optional<Number>;
value: String;
}>
Since v4.2.0

The props of a Combobox.

Details

  • open: whether the popup shows. The combobox only asks, with RequestedOpen and RequestedClose.
  • inputValue: the input's text. The combobox only asks, with RequestedInputValue.
  • items: every option, in the order they're drawn.
  • value: the selected value, or values with multiple. null when left out. The combobox only asks, with Picked.
  • multiple: more than one item can be selected, and picking one leaves the popup open unless the text filtered the list. False when left out.
  • filter: how the text matches the items. "contains" when left out.
  • filteredItems: the items to draw, from the consumer's own filter, in place of filter.
  • locale: the locale the filter compares in. The runtime's when left out.
  • limit: the most items drawn. All of them when left out.
  • autoHighlight: typing highlights the first match, so Enter picks it. False when left out.
  • highlightItemOnHover: the pointer highlights the item it's over. True when left out.
  • loopFocus: the arrow keys go past the ends of the list and around. True when left out.
  • openOnInputClick: a press on the input opens the popup. True when left out.
  • inputInPopup: the input is drawn inside the popup, and the trigger is the combobox. False when left out.
  • inline: the list is drawn without a popup and is always expanded. False when left out.
  • grid: the items are drawn in rows, by their row, and the list is a grid. False when left out.
  • virtualized: the consumer draws only some of the items, so the combobox doesn't scroll the highlighted one into view; scroll to it on Highlighted. False when left out.
  • placeholder: the value part's text while nothing is selected.
  • disabled, readOnly, required: as on a native <input>. A read-only combobox opens and can be browsed but not changed.
  • name, form, autoComplete: the form field.
  • id: the input's id, or the trigger's with inputInPopup, unless the builder has one. Generated when left out.
  • dir: the writing direction, for the horizontal arrow keys. When left out, the nearest DirectionProvider's or, without one, the CSS direction of the chips for the chip keys, and of the popup or an inline list for the item keys.
  • modal: while open, the page doesn't scroll, a press outside only closes the popup, and the rest of the page is hidden from assistive technology. With inputInPopup, the popup is also a modal dialog that Tab doesn't leave. False when left out.
  • dismissLabel: the name of the visually hidden dismiss button in the popup. "Dismiss" when left out.
  • removedLabel: announced after a chip's label once value drops it. "removed" when left out.
  • finalFocus: with inputInPopup, on close, focus goes back to the trigger, or to a finalFocus part. False leaves it where it is. True when left out.
  • holdExit: keeps the closing popup shown, for an exit animation the consumer ends by clearing it.
  • the Positioning.PositionerFields, for the popup, topLayer: false among them to draw it in place, as the module describes. side is "bottom" when left out, and the anchor is the input group, or the input without one, or the trigger with inputInPopup.

Signature

declare const ComboboxProps: Struct<{
readonly align: optional<Literals<readonly ["start", "center", "end"]>>;
readonly alignOffset: optional<Number>;
readonly anchor: optional<Union<readonly [String, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>>;
readonly arrowPadding: optional<Number>;
readonly autoComplete: optional<String>;
readonly autoHighlight: optional<Boolean>;
readonly collisionAvoidance: optional<Struct<{
readonly align: optional<Literals<readonly ["flip", "shift", "none"]>>;
readonly fallbackAxisSide: optional<Literals<readonly ["start", "end", "none"]>>;
readonly side: optional<Literals<readonly ["flip", "shift", "none"]>>;
}>>;
readonly collisionBoundary: optional<Union<readonly [Literal<"clipping-ancestors">, Struct<{
readonly id: String;
}>, Struct<{
readonly height: Number;
readonly width: Number;
readonly x: Number;
readonly y: Number;
}>]>>;
readonly collisionPadding: optional<Union<readonly [Number, Struct<{
readonly bottom: optional<Number>;
readonly left: optional<Number>;
readonly right: optional<Number>;
readonly top: optional<Number>;
}>]>>;
readonly dir: optional<Literals<readonly ["ltr", "rtl"]>>;
readonly disableAnchorTracking: optional<Boolean>;
readonly disabled: optional<Boolean>;
readonly dismissLabel: optional<String>;
readonly filter: optional<Literals<readonly ["contains", "startsWith", "endsWith", "none"]>>;
readonly filteredItems: optional<$Array<Struct<{
readonly disabled: optional<Boolean>;
readonly group: optional<String>;
readonly label: String;
readonly row: optional<Number>;
value: String;
}>>>;
readonly finalFocus: optional<Boolean>;
readonly form: optional<String>;
readonly grid: optional<Boolean>;
readonly highlightItemOnHover: optional<Boolean>;
readonly holdExit: optional<Boolean>;
readonly id: optional<String>;
readonly inline: optional<Boolean>;
readonly inputInPopup: optional<Boolean>;
readonly inputValue: String;
readonly items: $Array<Struct<{
readonly disabled: optional<Boolean>;
readonly group: optional<String>;
readonly label: String;
readonly row: optional<Number>;
value: String;
}>>;
readonly limit: optional<Number>;
readonly locale: optional<String>;
readonly loopFocus: optional<Boolean>;
readonly modal: optional<Boolean>;
readonly multiple: optional<Boolean>;
readonly name: optional<String>;
readonly open: Boolean;
readonly openOnInputClick: optional<Boolean>;
readonly placeholder: optional<String>;
readonly positionMethod: optional<Literals<readonly ["absolute", "fixed"]>>;
readonly readOnly: optional<Boolean>;
readonly removedLabel: optional<String>;
readonly required: optional<Boolean>;
readonly side: optional<Literals<readonly ["top", "bottom", "left", "right", "inline-start", "inline-end"]>>;
readonly sideOffset: optional<Number>;
readonly sticky: optional<Boolean>;
readonly topLayer: optional<Boolean>;
readonly value: optional<NullOr<Union<readonly [String, $Array<String>]>>>;
readonly virtualized: optional<Boolean>;
}>
Since v4.2.0

What a Combobox holds: the selected value, the values with multiple, or null for none.

Signature

declare const ComboboxValue: NullOr<Union<readonly [String, $Array<String>]>>