Select unstable
A button that opens a list of options, showing the selected one.
Details
Select is headless: it owns the keyboard and pointer behaviour, focus,
placement, the data attributes and the form inputs, and the consumer draws
the markup. The consumer owns whether the popup is open and what's
selected, passes them as open and value, and stores what the
RequestedOpen, RequestedClose and Picked events ask for. Values are
strings, and items lists every option with its label, in the order
they're drawn.
Anatomy:
| Part | Element |
|---|---|
label |
<div> that names the trigger |
trigger |
<button> that opens the popup |
value |
<span> inside the trigger, the selected label |
icon |
<span> inside the trigger |
backdrop |
<div>, a manual popover under the positioner |
positioner |
<div>, a manual popover placed by the select |
popup |
<div> inside the positioner |
list |
<div> inside the popup, when it holds more than items |
arrow |
<div> inside the popup |
item |
<div>, one per value, inside the popup or the list |
itemText |
<div> inside an item, its label |
itemIndicator |
<span> inside an item, shown while it's selected |
group |
<div> around items |
groupLabel |
<div> inside a group |
separator |
<div> between items |
scrollUpArrow |
<div> inside the popup |
scrollDownArrow |
<div> inside the popup |
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 and itemIndicator
take an options object, { element, value }, and group and
groupLabel take { element, group }, where group is the group of
the items inside. The scroll arrows take { element }. arrow,
itemIndicator and the scroll arrows return undefined while they're
hidden; a keepMounted field keeps the indicator and the scroll arrows
drawn. Every item value has to be in items, and item keys its
element with the value.
In a Field, wrap the trigger and the positioner in field.focusWithin
and draw the trigger with field.member, so focus moving into the popup
doesn't mark the field touched. Name it with select.label, not a field
label: select.label names the trigger, and a click on it focuses the
trigger without opening.
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.
CSS variables:
Set on the positioner:
--anchor-width,--anchor-height: the trigger's size--available-width,--available-height: the space between the trigger and the edge of the collision boundary, for amax-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, data-direction and
data-orientation, which hold a value:
trigger:data-popup-open,data-pressed,data-popup-side,data-disabled,data-readonly,data-required,data-placeholdervalue:data-placeholdericon:data-popup-openbackdrop:data-open/data-closed,data-starting-style,data-ending-stylepositioner:data-open/data-closed,data-starting-style,data-ending-style,data-side,data-align,data-anchor-hiddenpopup,arrow: as on the positioner, withoutdata-anchor-hidden; the arrow addsdata-uncentereditem:data-selected,data-highlighted,data-disabledseparator:data-orientationscrollUpArrow,scrollDownArrow:data-direction,data-side,data-visible
data-side is none while the popup is aligned with the trigger.
Keyboard:
On the trigger, Enter, Space, ArrowDown and ArrowUp open the popup and
move focus to the selected item, or to the first or, for ArrowUp, the
last item. Inside a vertical Toolbar, ArrowDown and ArrowUp move focus
instead. Typing a letter selects the next matching item without
opening. In the popup, ArrowDown, ArrowUp, Home and End move between
items, disabled ones included, and typing moves to the next item whose
label starts with what's typed, skipping disabled ones. Enter and Space
pick the focused item. Escape closes the popup, and Shift+Tab closes it
and returns focus to the trigger.
Placement:
By default the popup covers the trigger, with the selected item over the
trigger's text, and grows as its list scrolls. It falls back to placing
the popup below the trigger when the trigger is within 20px of the top
or bottom of the viewport, when there's no room for the popup's
min-height (100px when unset), and for a select opened by touch.
While aligned, the positioner's margin-top and margin-bottom in CSS
are the gaps it keeps to the top and bottom of the viewport, 10px each
when unset. A margin of 0 puts it against that edge, also when the 0
comes from a reset such as * { margin: 0 }. A resize of the window
closes an aligned popup. Set
alignItemWithTrigger: false to always place it next to the trigger,
where the Positioning props apply and it flips when it doesn't fit.
In place:
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 select is never modal or aligned with
its trigger, whatever modal and alignItemWithTrigger say.
Form:
With name, required or autoComplete, the trigger 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. A multiple select submits one hidden input per
value. A modal select locks the page's scroll and blocks presses
outside, except on the trigger. An empty string counts as no value.
Example A theme picker in a field, with the open state and the value in the consumer's Model
import { UiSchema } from "effect/ui"import { Html, HtmlServer } from "effect/ui/html"import { Field, Select } from "effect/ui/kit"import { Effect, Schema } from "effect"
const themes = [ { value: "light", label: "Light" }, { value: "dark", label: "Dark" }, { value: "system", label: "System" }]
const SettingsMessage = UiSchema.TaggedEnum({ RequestedOpenTheme: {}, RequestedCloseTheme: {}, PickedTheme: { theme: Schema.String }})
const Settings = Html.component({ name: "Settings", model: Schema.Struct({ open: Schema.Boolean, theme: Schema.String }), message: SettingsMessage}).make({ init: () => ({ open: false, theme: "system" }), update: { RequestedOpenTheme: ($) => $.evolve({ open: true }), RequestedCloseTheme: ($) => $.evolve({ open: false }), PickedTheme: ($, { theme }) => $.evolve({ theme }) }, view: (h, model) => Field(h, { props: { filled: true }, view: (field) => Select(h, { props: { open: model.open, value: model.theme, items: themes, name: "theme", disabled: field.disabled }, onEmit: { RequestedOpen: () => SettingsMessage.RequestedOpenTheme(), RequestedClose: () => SettingsMessage.RequestedCloseTheme(), Picked: ({ value }) => SettingsMessage.PickedTheme({ theme: String(value) }), Settled: () => undefined }, view: (select) => field.root(h.div).children( select.label(h.div).children("Theme"), field.focusWithin(h.div).children( select.trigger(field.member(h.button)).children(select.value(h.span), select.icon(h.span).children("โพ")), select.positioner(h.div).children( select.popup(h.div).children( themes.map(({ label, value }) => select.item({ element: h.div, value }).children( select.itemText(h.div).children(label), select.itemIndicator({ element: h.span, value })?.children("โ") ) ) ) ) ) ) }) })})
// The trigger is a combobox that shows the selected theme.const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Settings, {}))if (!/<button[^>]* role="combobox"[^>]*>.*System/.test(html)) throw new Error("the trigger doesn't show the theme")Components
makeSelect
unstableCreates a select whose selected values, items, item and itemIndicator
parts and Picked event use the supplied string-valued schema. 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 Select export
uses Schema.String.
Signature
declare function makeSelect<V extends string>(options: { readonly value: Codec<V, string>;}): Headless<{ readonly align?: "start" | "end" | "center"; readonly alignItemWithTrigger?: boolean; 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 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 disableAnchorTracking?: boolean; readonly disabled?: boolean; readonly dismissLabel?: string; readonly finalFocus?: boolean; readonly form?: string; readonly highlightItemOnHover?: boolean; readonly holdExit?: boolean; readonly id?: string; readonly items: readonly Array<{ readonly disabled?: boolean; readonly label: string; value: V; }>; readonly modal?: boolean; readonly multiple?: boolean; readonly name?: string; readonly open: boolean; readonly placeholder?: string; readonly positionMethod?: "fixed" | "absolute"; readonly readOnly?: boolean; 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 _tag: "Settled"; readonly open: boolean;} | { readonly _tag: "RequestedOpen"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize";} | { readonly _tag: "RequestedClose"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize";} | { readonly _tag: "Picked"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize"; readonly value: V | readonly Array<V> | null;}, { align: "start" | "end" | "center"; alignedWithTrigger: boolean; arrow: <B extends PartTarget<"div">>(element: B) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; backdrop: Part<"div", [], never>; disabled: boolean; 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">; highlighted: V | null; icon: Part<"span", [], 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">; itemText: Part<"div", [], never>; label: Part<"div", [], never>; list: Part<"div", [], never>; 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; scrollDownArrow: <B extends PartTarget<"div">>(__namedParameters: { readonly element: B; readonly keepMounted?: boolean; }) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; scrollUpArrow: <B extends PartTarget<"div">>(__namedParameters: { readonly element: B; readonly keepMounted?: boolean; }) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; selected: V | readonly Array<V> | null; separator: Part<"div", [], never>; side: string; transitionStatus: SelectTransitionStatus; 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 closeMethod: "mouse" | "touch" | "pen" | "keyboard" | null; readonly fellBack: boolean; 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: boolean; readonly pressing: boolean; readonly releaseSelected: boolean; readonly releaseUnselected: boolean; readonly scrollDown: boolean; readonly scrollUp: boolean; readonly spaceDown: boolean; readonly started: boolean; readonly typeahead: { readonly matched: number; readonly typed: string; readonly typedFrom: number; };}, { readonly _tag: "RenderedFirstFrame";} | { readonly _tag: "FocusedOutside";} | { readonly _tag: "BlurredTrigger";} | { readonly _tag: "FocusedInput";} | { readonly _tag: "ReleasedTrigger";} | { readonly _tag: "ClickedLabel";} | { readonly _tag: "LeftItem";} | { readonly _tag: "PressedDismiss";} | { readonly _tag: "CompletedWaitBeforeResetTyping";} | { readonly _tag: "ShowedPopup";} | { readonly _tag: "PressedItem";} | { readonly _tag: "AllowedRelease";} | { readonly _tag: "ClickedTrigger"; readonly pointerType: string;} | { readonly _tag: "FinishedTransition"; readonly open: boolean;} | { readonly _tag: "PressedOutside"; readonly pointerType: string;} | { readonly _tag: "PressedTrigger"; readonly pointerType: string;} | { readonly _tag: "PressedTriggerKey"; readonly key: string;} | { readonly _tag: "Autofilled"; readonly value: string;} | { readonly _tag: "EnteredItem"; readonly value: string;} | { readonly _tag: "ReleasedItem"; readonly pointerType: string; readonly value: string;} | { readonly _tag: "ClickedItem"; readonly pointerType: string; readonly value: string;} | { 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: "ReleasedSpace";} | { readonly _tag: "FocusedTrigger";} | { readonly _tag: "PressedPopupKey"; readonly key: string;} | { readonly _tag: "ResizedWindow";} | { readonly _tag: "FellBack";} | { readonly _tag: "ChangedScrollArrows"; readonly down: boolean; readonly up: boolean;} | { readonly _tag: "ScrolledByArrow";} | { readonly _tag: "DraggedPointer";}, QueryEntries<{}, {}>>Example A select typed by a literal union
import { UiSchema } from "effect/ui"import { Html, HtmlServer } from "effect/ui/html"import { makeSelect } from "effect/ui/kit"import { Effect, Schema } from "effect"
const Theme = Schema.Literals(["light", "dark"])const ThemeSelect = makeSelect({ value: Theme })const items = [{ value: "light", label: "Light" }, { value: "dark", label: "Dark" }] as const
const Message = UiSchema.TaggedEnum({ PickedTheme: { theme: Theme }, Toggled: { open: Schema.Boolean }})
const Settings = Html.component({ name: "Settings", model: Schema.Struct({ theme: Theme, open: Schema.Boolean }), message: Message}).make({ init: () => ({ theme: "light" as const, open: false }), update: { PickedTheme: ($, { theme }) => $.evolve({ theme }), Toggled: ($, { open }) => $.evolve({ open }) }, view: (h, model) => ThemeSelect(h, { props: { open: model.open, value: model.theme, items }, onEmit: { // `value` is "light" | "dark" | ReadonlyArray<"light" | "dark"> | null Picked: ({ value }) => typeof value === "string" ? Message.PickedTheme({ theme: value }) : undefined, RequestedOpen: () => Message.Toggled({ open: true }), RequestedClose: () => Message.Toggled({ open: false }), Settled: () => undefined }, view: (select) => select.trigger(h.button).children(select.value(h.span)) })})
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Settings, {}))if (!html.includes("Light")) throw new Error("the trigger doesn't show the value")A select: a button that opens a list of options, the selected one shown on the button.
Details
The parts also return plain values for markup that depends on them:
open, mounted (the popup shows, through its exit transition),
transitionStatus, selected (the value prop, or null),
placeholder (nothing is selected), disabled, readOnly,
required, multiple, side and align (where the popup ended up,
side being "none" while it's aligned with the trigger),
alignedWithTrigger, highlighted (the value of the item with focus) and
openMethod, which is null once the popup closes.
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:
trigger:id, which theidprop sets,type="button",role="combobox",aria-haspopup="listbox",aria-expanded,aria-readonly,aria-required,disabled, noaria-disabled,aria-controlswhile open, pointing at the list or else the popup, andaria-labelledbypointing atlabelunless the builder has onelabel:idbackdrop,positioner:role="presentation"andpopover="manual"popup:id,tabindex="-1", androle="listbox",aria-multiselectable,aria-readonlyandaria-labelledbypointing atlabelunless the builder has a name, orrole="presentation"when alistis drawn inside itlist:id,role="listbox",aria-multiselectable,aria-readonly, andaria-labelledbyas on the popupitem:id,role="option",aria-selected,aria-disabled, andtabindex,"0"while it's highlighted in an open popup and"-1"otherwisegroup:role="group"andaria-labelledbypointing at itsgroupLabelgroupLabel:idandaria-hidden="true"icon,arrow,itemIndicator,scrollUpArrow,scrollDownArrow:aria-hidden="true", andidon the arrowseparator:role="separator",aria-orientation="horizontal"
With 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:
trigger:mousedown,mouseup,clickandkeydownlabel:clickpopup:keydownandkeyupitem:pointerenter,pointerleave,mousedown,mouseupandclick
The trigger and the popup cancel the keys they handle. The positioner's
mount places the popup, moves focus into it, scrolls it and listens for
presses and focus outside it. If it opens during mousedown, it cancels
the default action to keep focus in the popup.
It emits RequestedOpen, RequestedClose, Picked and Settled.
History restore saves nothing of it: after Back, forward or a reload it
starts from init.
Signature
declare const Select: Headless<{ readonly align?: "start" | "end" | "center"; readonly alignItemWithTrigger?: boolean; 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 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 disableAnchorTracking?: boolean; readonly disabled?: boolean; readonly dismissLabel?: string; readonly finalFocus?: boolean; readonly form?: string; readonly highlightItemOnHover?: boolean; readonly holdExit?: boolean; readonly id?: string; readonly items: readonly Array<{ readonly disabled?: boolean; readonly label: string; value: string; }>; readonly modal?: boolean; readonly multiple?: boolean; readonly name?: string; readonly open: boolean; readonly placeholder?: string; readonly positionMethod?: "fixed" | "absolute"; readonly readOnly?: boolean; 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 _tag: "Settled"; readonly open: boolean;} | { readonly _tag: "RequestedOpen"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize";} | { readonly _tag: "RequestedClose"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize";} | { readonly _tag: "Picked"; readonly reason: "none" | "trigger-press" | "outside-press" | "escape-key" | "close-press" | "focus-out" | "item-press" | "list-navigation" | "cancel-open" | "window-resize"; readonly value: string | readonly Array<string> | null;}, { align: "start" | "end" | "center"; alignedWithTrigger: boolean; arrow: <B extends PartTarget<"div">>(element: B) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; backdrop: Part<"div", [], never>; disabled: boolean; 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">; highlighted: string | null; icon: Part<"span", [], 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">; itemText: Part<"div", [], never>; label: Part<"div", [], never>; list: Part<"div", [], never>; 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; scrollDownArrow: <B extends PartTarget<"div">>(__namedParameters: { readonly element: B; readonly keepMounted?: boolean; }) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; scrollUpArrow: <B extends PartTarget<"div">>(__namedParameters: { readonly element: B; readonly keepMounted?: boolean; }) => ReturnType<B["attr"]> | undefined & Pick<Part<"div", [], never>, "~R">; selected: string | readonly Array<string> | null; separator: Part<"div", [], never>; side: string; transitionStatus: SelectTransitionStatus; trigger: Part<"button", [], never>; value: Part<"span", [], never>;}, never, never, never, never, never, never, { readonly active: string | null; readonly activeByKey: boolean; readonly closeMethod: "mouse" | "touch" | "pen" | "keyboard" | null; readonly fellBack: boolean; 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: boolean; readonly pressing: boolean; readonly releaseSelected: boolean; readonly releaseUnselected: boolean; readonly scrollDown: boolean; readonly scrollUp: boolean; readonly spaceDown: boolean; readonly started: boolean; readonly typeahead: { readonly matched: number; readonly typed: string; readonly typedFrom: number; };}, { readonly _tag: "RenderedFirstFrame";} | { readonly _tag: "FocusedOutside";} | { readonly _tag: "BlurredTrigger";} | { readonly _tag: "FocusedInput";} | { readonly _tag: "ReleasedTrigger";} | { readonly _tag: "ClickedLabel";} | { readonly _tag: "LeftItem";} | { readonly _tag: "PressedDismiss";} | { readonly _tag: "CompletedWaitBeforeResetTyping";} | { readonly _tag: "ShowedPopup";} | { readonly _tag: "PressedItem";} | { readonly _tag: "AllowedRelease";} | { readonly _tag: "ClickedTrigger"; readonly pointerType: string;} | { readonly _tag: "FinishedTransition"; readonly open: boolean;} | { readonly _tag: "PressedOutside"; readonly pointerType: string;} | { readonly _tag: "PressedTrigger"; readonly pointerType: string;} | { readonly _tag: "PressedTriggerKey"; readonly key: string;} | { readonly _tag: "Autofilled"; readonly value: string;} | { readonly _tag: "EnteredItem"; readonly value: string;} | { readonly _tag: "ReleasedItem"; readonly pointerType: string; readonly value: string;} | { readonly _tag: "ClickedItem"; readonly pointerType: string; readonly value: string;} | { 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: "ReleasedSpace";} | { readonly _tag: "FocusedTrigger";} | { readonly _tag: "PressedPopupKey"; readonly key: string;} | { readonly _tag: "ResizedWindow";} | { readonly _tag: "FellBack";} | { readonly _tag: "ChangedScrollArrows"; readonly down: boolean; readonly up: boolean;} | { readonly _tag: "ScrolledByArrow";} | { readonly _tag: "DraggedPointer";}, QueryEntries<{}, {}>>Models
Why a Select asks to open, close or change its value.
Signature
type SelectChangeReason = typeof SelectChangeReason.TypeWhat a Select emits.
Signature
type SelectEvents<V extends string = string> = SelectEventsSchema<V>["Type"]How the select was opened or closed.
Signature
type SelectInteraction = typeof SelectInteraction.TypeOne option of a Select.
Signature
type SelectItem<V extends string = string> = ReturnType<typeof itemSchema>["Type"]The props of a Select.
Signature
type SelectProps<V extends string = string> = ReturnType<typeof propsSchema>["Type"]Where a select's popup is in its transitions: "starting" for the
first frame after it opens, "ending" while it closes, null otherwise.
Signature
type SelectTransitionStatus = "starting" | "ending" | nullWhat a Select holds.
Signature
type SelectValue<V extends string = string> = ReturnType<typeof valueSchema>["Type"]Schemas
SelectChangeReason
unstableWhy a Select asks to open, close or change its value.
Details
"trigger-press": a press, or Enter or Space, on the trigger"list-navigation": ArrowDown or ArrowUp on the closed trigger"item-press": an item was picked"outside-press": a press outside the trigger and the popup, other than on a scrollbar"escape-key": Escape in the popup or on the open trigger"focus-out": focus left the trigger and the popup, or Shift+Tab in the popup"close-press": the visually hidden dismiss button in amodalpopup, for screen readers"cancel-open": the press that opened it was released away from the trigger and the popup"window-resize": the window resized while the popup covered the trigger"none": typeahead on the closed trigger, autofill, or focus coming back to the trigger while the popup covers it
Signature
declare const SelectChangeReason: Literals<readonly ["trigger-press", "list-navigation", "item-press", "outside-press", "escape-key", "focus-out", "close-press", "cancel-open", "window-resize", "none"]>SelectEvents
unstableWhat a Select emits.
Details
RequestedOpen: asks foropento be true.RequestedClose: asks foropento be false.Picked: asks forvalueto bevalue, the whole new selection.Settled: reports that the popup's transitions ended, after it opened or closed.
Signature
declare const SelectEvents: TaggedEnum<{ Picked: TaggedStruct<"Picked", { readonly reason: Literals<readonly ["trigger-press", "list-navigation", "item-press", "outside-press", "escape-key", "focus-out", "close-press", "cancel-open", "window-resize", "none"]>; readonly value: NullOr<Union<readonly [String, $Array<String>]>>; }>; RequestedClose: TaggedStruct<"RequestedClose", { readonly reason: Literals<readonly ["trigger-press", "list-navigation", "item-press", "outside-press", "escape-key", "focus-out", "close-press", "cancel-open", "window-resize", "none"]>; }>; RequestedOpen: TaggedStruct<"RequestedOpen", { readonly reason: Literals<readonly ["trigger-press", "list-navigation", "item-press", "outside-press", "escape-key", "focus-out", "close-press", "cancel-open", "window-resize", "none"]>; }>; Settled: TaggedStruct<"Settled", { readonly open: Boolean; }>;}>SelectInteraction
unstableHow the select was opened or closed: "keyboard" for a key or a click
from no pointer.
Signature
declare const SelectInteraction: Literals<readonly ["mouse", "touch", "pen", "keyboard"]>SelectItem
unstableOne option of a Select: the value it submits, the text the trigger shows
and typeahead matches, and whether it can be picked.
Signature
declare const SelectItem: Struct<{ readonly disabled: optional<Boolean>; readonly label: String; value: String;}>SelectProps
unstableThe props of a Select.
Details
open: whether the popup shows. The select only asks, withRequestedOpenandRequestedClose.items: every option, in the order they're drawn. Navigation, typeahead and the trigger's text read them, so list each item drawn.value: the selected value, or values withmultiple.nullwhen left out. The select only asks, withPicked.multiple: more than one item can be selected, and picking one leaves the popup open. False when left out.placeholder: the trigger's text while nothing is selected.disabled,readOnly,required: as on a native<select>. A read-only select opens and can be browsed but not changed.name,form,autoComplete: the form field.id: the trigger's id. Generated when left out.modal: while open, the page doesn't scroll, a press outside only closes the popup, and screen readers see only the trigger and the popup. True when left out.dismissLabel: the name of the visually hidden dismiss button in amodalpopup."Dismiss"when left out.highlightItemOnHover: the pointer highlights the item it's over. True when left out.alignItemWithTrigger: the popup covers the trigger, with the selected item over the trigger's text. True when left out. It's off for a select opened by touch, and falls back to placing the popup next to the trigger when there isn't room.finalFocus: on close, focus goes back to the trigger, or to afinalFocuspart. 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 when it isn't aligned with the trigger.sideis"bottom"when left out.topLayer: falsedraws the backdrop and the positioner in place, as the module describes.
Signature
declare const SelectProps: Struct<{ readonly align: optional<Literals<readonly ["start", "center", "end"]>>; readonly alignItemWithTrigger: optional<Boolean>; 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 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 disableAnchorTracking: optional<Boolean>; readonly disabled: optional<Boolean>; readonly dismissLabel: optional<String>; readonly finalFocus: optional<Boolean>; readonly form: optional<String>; readonly highlightItemOnHover: optional<Boolean>; readonly holdExit: optional<Boolean>; readonly id: optional<String>; readonly items: $Array<Struct<{ readonly disabled: optional<Boolean>; readonly label: String; value: String; }>>; readonly modal: optional<Boolean>; readonly multiple: optional<Boolean>; readonly name: optional<String>; readonly open: Boolean; readonly placeholder: optional<String>; readonly positionMethod: optional<Literals<readonly ["absolute", "fixed"]>>; readonly readOnly: optional<Boolean>; 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>]>>>;}>SelectValue
unstableWhat a Select holds: one value, the values of a multiple select, or
null for none. An empty string counts as no value too.
Signature
declare const SelectValue: NullOr<Union<readonly [String, $Array<String>]>>