Innate UIv0.1.0
Inputs

Select

A custom single or multiple selection control with a popup listbox.

Example

The preview is interactive. The code below it is the docs demo source; demo-only layout classes can be omitted in application code.

tsx
import { Cell, For } from "retend";

import { Field, Select } from "innate-ui";
import classes from "../docs.module.css";

type ReleaseChannel = "" | "stable" | "beta" | "canary";
type Platform = "web" | "ios" | "android";

const releaseChannels = ["stable", "beta", "canary"] as const;
const platforms = ["web", "ios", "android"] as const;

export function SelectDemo() {
  const releaseChannel = Cell.source<ReleaseChannel>("");
  const selectedPlatforms = Cell.source<ReadonlyArray<Platform>>(["web"]);

  return (
    <div class={classes.selectDemo}>
      <Field id="release-channel-field" class={classes.selectExample}>
        <Field.Label>Release channel</Field.Label>
        <Select
          id="release-channel-select"
          value={releaseChannel}
          onChange={(value) => releaseChannel.set(value)}
          placeholder="Select channel"
        >
          {For(releaseChannels, (channel) => (
            <Select.Option value={channel}>{channel}</Select.Option>
          ))}
        </Select>
      </Field>

      <Field id="platform-field" class={classes.selectExample}>
        <Field.Label>Target platforms</Field.Label>
        <Select
          id="platform-select"
          multiple
          value={selectedPlatforms}
          onChange={(value) => selectedPlatforms.set(value)}
          placeholder="Select platforms"
        >
          {For(platforms, (platform) => (
            <Select.Option value={platform}>{platform}</Select.Option>
          ))}
        </Select>
      </Field>
    </div>
  );
}

API reference

This table is generated from Innate UI's exported TypeScript declarations and JSDoc. Native element attributes inherited by a prop type are not repeated here.

SelectProps

PropTypeDefault
valuerequired

Selected option value. Selected option values.

JSX.ValueOrCell<Value> | JSX.ValueOrCell<ReadonlyArray<Value>>
multiple

Enables multiple selection when `true`. Enables multiple selection.

false | truefalse
onChange

Called when a different option is selected. Called with the next selected-value array.

(value: Value) => void | (value: ReadonlyArray<Value>) => void
idrequired

Stable id used to connect the trigger and listbox.

string
childrenrequired

`Select.Option` children.

JSX.Children
open

Whether the listbox is open.

JSX.ValueOrCell<boolean>
placeholder

Trigger placeholder shown when no value is selected.

JSX.ValueOrCell<string>"Select an option"
disabled

Whether the select is disabled.

JSX.ValueOrCell<boolean>false
invalid

Whether the select is in an invalid state.

JSX.ValueOrCell<boolean>false
ariaDescribedBy

Ids of elements that describe the trigger.

JSX.ValueOrCell<string | undefined>
onOpenChange

Called when the listbox requests an open-state change.

(open: boolean, reason?: PopoverCloseReason) => void

SelectOptionProps

PropTypeDefault
valuerequired

Value represented by this option.

Value
childrenrequired

Option content.

JSX.Children
textValue

Display/typeahead text when it cannot be inferred from `children`.

JSX.ValueOrCell<string>
disabled

Whether the option is disabled.

JSX.ValueOrCell<boolean>false
ref

Receives the option button element.

SourceCell<HTMLButtonElement | null>
onClick

Click handler called before selection.

EventHandlerProp<HTMLButtonElement, MouseEvent>
onPointerMove

Pointer-move handler called before active-option tracking.

EventHandlerProp<HTMLButtonElement, PointerEvent>
Inspect the typed source →