Select

Picks one value from a list. The trigger is the base Field box, and it sits in a Field for its label, hint and error; the list is a popout with the menu's rows. Built on ui-sdk's Select: arrow keys and typing move through it, Enter chooses, Escape closes, and the value submits with its form. A new choice crossfades into the field without changing its width, and a just-chosen row's tick draws itself in.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

size
placeholder
disabled
readOnly

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it to pick one value from a list a person can scan, like a matter type or a practice area. Use Combobox when people search by typing, like a contact by name.
DoPut SelectSearch first in a long list, like every matter type a firm has, and SelectEmpty after SelectItems to say when nothing matches.
DoPut the trigger in a Field for its label, hint and error. Alone, like a table filter, name it with aria-label.
DoGroup items under a SelectLabel inside SelectGroup, like Recent above the full list, and divide groups with SelectSeparator.
Don'tUse it for two or three options a person compares, like Yes or No. Use RadioGroup or SegmentedControl, so every choice shows without a click.
Don'tAdd a tick or check icon to SelectItem. The selected row already shows its tick on the right.

Props

Select takes ui-sdk's options: value, defaultValue, onValueChange, multiple, placeholder, items, disabled, readOnly, required, name and the search options (query, filter, status). SelectContent takes side, align and alignItemWithTrigger.

SelectTrigger

PropTypeDefaultDescription
childrenReactNode—Usually a SelectValue.
size"xs" | "sm" | "md" | "lg""md"xs 28 · sm 32 · md 36 for forms · lg 40.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SelectValue

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SelectContent

PropTypeDefaultDescription
childrenReactNode—What it shows inside.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SelectItem

PropTypeDefaultDescription
childrenReactNode—What it shows inside.
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SelectLabel

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

SelectSearch

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@leap-crm/design-system";

<Select placeholder="Choose a matter type">
  <SelectTrigger aria-label="Matter type">
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="Conveyancing">Conveyancing</SelectItem>
    <SelectItem value="Family law">Family law</SelectItem>
  </SelectContent>
</Select>

States

Hover darkens the border, keyboard focus is the blue edge and halo, an error turns it red (with a red halo on focus), read-only is grey and keeps its value, disabled is 50%.

Please choose a matter type

Long list

A list taller than the room it has scrolls under the overlay scrollbar, which takes no space and fades when idle. Arrow keys keep the highlighted option in view.

Groups and search

A search field at the top filters the list, groups sit under quiet labels with a divider between them, and an empty search says so.

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { Fragment } from "react";

import { Field, Select, SelectContent, SelectEmpty, SelectGroup, SelectItem, SelectItems, SelectLabel, SelectSearch, SelectSeparator, SelectTrigger, SelectValue } from "@leap-crm/design-system";

const matterTypes = [
  "Conveyancing",
  "Family law",
  "Wills and estates",
  "Commercial",
  "Litigation",
] as const;

const sizes = ["xs", "sm", "md", "lg"] as const;

const allMatterTypes = [
  "Administrative law",
  "Body corporate",
  "Building and construction",
  "Commercial",
  "Commercial leasing",
  "Conveyancing",
  "Criminal law",
  "Debt recovery",
  "Employment",
  "Family law",
  "Immigration",
  "Insolvency",
  "Intellectual property",
  "Litigation",
  "Personal injury",
  "Planning and environment",
  "Powers of attorney",
  "Probate",
  "Wills and estates",
  "Workers compensation",
] as const;

function MatterType({
  size = "md",
  invalid = false,
  disabled = false,
  readOnly = false,
}: {
  size?: (typeof sizes)[number];
  invalid?: boolean;
  disabled?: boolean;
  readOnly?: boolean;
}) {
  return (
    <Select defaultValue="Conveyancing" disabled={disabled} readOnly={readOnly}>
      <Field
        label="Matter type"
        className="w-64"
        error={invalid ? "Please choose a matter type" : undefined}
      >
        <SelectTrigger size={size}>
          <SelectValue />
        </SelectTrigger>
      </Field>
      <SelectContent>
        {matterTypes.map(type => (
          <SelectItem key={type} value={type}>
            {type}
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  );
}

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
EnterSpaceOpen the list and focus the first item.
Arrow keysMove focus through the items, skipping disabled ones.
HomeEndMove to the first and last items.
TypingFocuses the next item that starts with the text.
EnterSpaceChoose the focused item.
EscapeCloses without choosing and returns focus to the trigger.