Select

A field that opens a list of options to pick one from, on Radix Select.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items: { value: string; label: string }[] = [
  { value: "item-1", label: "Item 1" },
  { value: "item-2", label: "Item 2" },
  { value: "item-3", label: "Item 3" },
  { value: "item-4", label: "Item 4" },
  { value: "item-5", label: "Item 5" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="select-preview">Label</Label>
    <Select>
      <SelectTrigger id="select-preview">
        <SelectValue placeholder="Placeholder" />
      </SelectTrigger>
      <SelectContent>
        <SelectGroup>
          {items.map((item) => (
            <SelectItem key={item.value} value={item.value}>
              {item.label}
            </SelectItem>
          ))}
        </SelectGroup>
      </SelectContent>
    </Select>
  </div>
);

export default Example;

Usage

import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";
<Select>
  <SelectTrigger className="w-45">
    <SelectValue placeholder="Placeholder" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectItem value="apple">Item 1</SelectItem>
      <SelectItem value="banana">Item 2</SelectItem>
      <SelectItem value="blueberry">Item 3</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

Examples

Appearances

appearance paints the field on the kit's one scale: solid, the default, soft on the grey wash, outline with only its line, and transparent with neither until it is hovered.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
  type SelectTriggerAppearance,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { appearance: SelectTriggerAppearance; label: string }[] = [
  { appearance: "solid", label: "Solid" },
  { appearance: "soft", label: "Soft" },
  { appearance: "outline", label: "Outline" },
  { appearance: "transparent", label: "Transparent" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.appearance}>
        <Label htmlFor={`select-appearance-${variant.appearance}`}>
          {variant.label}
        </Label>
        <Select>
          <SelectTrigger
            id={`select-appearance-${variant.appearance}`}
            appearance={variant.appearance}
          >
            <SelectValue placeholder="Placeholder" />
          </SelectTrigger>
          <SelectContent>
            {items.map((item) => (
              <SelectItem key={item} value={item}>
                {item}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </div>
    ))}
  </div>
);

export default Example;

Sizes

size sets its height: sm 32px, base 40px (the default) or lg 48px, a Button's height at the same size, the large one written at 16px on a phone.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
  type SelectTriggerSize,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { size: SelectTriggerSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.size}>
        <Label htmlFor={`select-size-${variant.size}`}>{variant.label}</Label>
        <Select>
          <SelectTrigger id={`select-size-${variant.size}`} size={variant.size}>
            <SelectValue placeholder="Placeholder" />
          </SelectTrigger>
          <SelectContent>
            {items.map((item) => (
              <SelectItem key={item} value={item}>
                {item}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </div>
    ))}
  </div>
);

export default Example;

Border radius

borderRadius sets its corners on the kit's one scale: none, xs 4px, sm 6px, base 8px (the default), lg 12px, xl 16px, or full to round it.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
  type SelectTriggerBorderRadius,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3"];

const variants: { borderRadius: SelectTriggerBorderRadius; label: string }[] = [
  { borderRadius: "none", label: "None" },
  { borderRadius: "xs", label: "xs" },
  { borderRadius: "sm", label: "sm" },
  { borderRadius: "base", label: "base" },
  { borderRadius: "lg", label: "lg" },
  { borderRadius: "xl", label: "xl" },
  { borderRadius: "full", label: "full" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.borderRadius}>
        <Label htmlFor={`select-radius-${variant.borderRadius}`}>
          {variant.label}
        </Label>
        <Select>
          <SelectTrigger
            id={`select-radius-${variant.borderRadius}`}
            borderRadius={variant.borderRadius}
          >
            <SelectValue placeholder="Placeholder" />
          </SelectTrigger>
          <SelectContent>
            {items.map((item) => (
              <SelectItem key={item} value={item}>
                {item}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </div>
    ))}
  </div>
);

export default Example;

With icon

An Icon inside a SelectItem sits before its text, in the list and in the field once it is picked.

import {
  File01Icon,
  Folder01Icon,
  Image01Icon,
} from "@hugeicons/core-free-icons";
import { Icon, type IconSvgElement } from "@produkto/ui/Icon";
import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items: { value: string; label: string; icon: IconSvgElement }[] = [
  { value: "item-1", label: "Item 1", icon: Folder01Icon },
  { value: "item-2", label: "Item 2", icon: File01Icon },
  { value: "item-3", label: "Item 3", icon: Image01Icon },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="select-icon">Label</Label>
    <Select defaultValue="item-1">
      <SelectTrigger id="select-icon">
        <SelectValue placeholder="Placeholder" />
      </SelectTrigger>
      <SelectContent>
        {items.map((item) => (
          <SelectItem key={item.value} value={item.value}>
            <Icon icon={item.icon} />
            {item.label}
          </SelectItem>
        ))}
      </SelectContent>
    </Select>
  </div>
);

export default Example;

Groups

SelectGroup gathers items under a SelectLabel no one can pick, and SelectSeparator draws a line between the groups.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";
import { Fragment } from "react";

const groups: { label: string; items: string[] }[] = [
  { label: "Group 1", items: ["Item 1", "Item 2", "Item 3"] },
  { label: "Group 2", items: ["Item 4", "Item 5", "Item 6"] },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="select-groups">Label</Label>
    <Select>
      <SelectTrigger id="select-groups">
        <SelectValue placeholder="Placeholder" />
      </SelectTrigger>
      <SelectContent>
        {groups.map((group, index) => (
          <Fragment key={group.label}>
            {index > 0 ? <SelectSeparator /> : null}
            <SelectGroup>
              <SelectLabel>{group.label}</SelectLabel>
              {group.items.map((item) => (
                <SelectItem key={item} value={item}>
                  {item}
                </SelectItem>
              ))}
            </SelectGroup>
          </Fragment>
        ))}
      </SelectContent>
    </Select>
  </div>
);

export default Example;

Position

position on SelectContent sets where the list opens: "popper", the default, under the field like the menus, or "item-aligned" over the field with the picked item on it.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  type SelectContentProps,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"];

const variants: {
  position: SelectContentProps["position"];
  label: string;
}[] = [
  { position: "popper", label: "Popper" },
  { position: "item-aligned", label: "Item aligned" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.position}>
        <Label htmlFor={`select-position-${variant.position}`}>
          {variant.label}
        </Label>
        <Select defaultValue="Item 3">
          <SelectTrigger id={`select-position-${variant.position}`}>
            <SelectValue placeholder="Placeholder" />
          </SelectTrigger>
          <SelectContent position={variant.position}>
            {items.map((item) => (
              <SelectItem key={item} value={item}>
                {item}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      </div>
    ))}
  </div>
);

export default Example;

Clearable

clearable on the SelectTrigger swaps the arrow for an X while something is picked, which empties it, or puts back resetTo on the Select, and gives the field the focus back; by default a field has none.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-clearable-off">Label</Label>
      <Select defaultValue="Item 1">
        <SelectTrigger id="select-clearable-off">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem key={item} value={item}>
              {item}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-clearable">Label</Label>
      <Select defaultValue="Item 1">
        <SelectTrigger clearable id="select-clearable">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem key={item} value={item}>
              {item}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
  </div>
);

export default Example;

Disabled

disabled on the Select dims the field and keeps its list shut, beside one as it is by default; on a SelectItem it greys that row out, as Item 3 here, and the arrow keys pass it by.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items: { value: string; disabled?: boolean }[] = [
  { value: "Item 1" },
  { value: "Item 2" },
  { value: "Item 3", disabled: true },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-enabled">Label</Label>
      <Select>
        <SelectTrigger id="select-enabled">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem
              disabled={item.disabled}
              key={item.value}
              value={item.value}
            >
              {item.value}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-disabled">Label</Label>
      <Select disabled>
        <SelectTrigger id="select-disabled">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem key={item.value} value={item.value}>
              {item.value}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
  </div>
);

export default Example;

Invalid

error on the SelectTrigger writes what is wrong under it, turns its border to the destructive colour and describes it to screen readers, beside one without an error.

import { Label } from "@produkto/ui/Label";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@produkto/ui/Select";

const items = ["Item 1", "Item 2", "Item 3"];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-valid">Label</Label>
      <Select>
        <SelectTrigger id="select-valid">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem key={item} value={item}>
              {item}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="select-error">Label</Label>
      <Select>
        <SelectTrigger error="Description" id="select-error">
          <SelectValue placeholder="Placeholder" />
        </SelectTrigger>
        <SelectContent>
          {items.map((item) => (
            <SelectItem key={item} value={item}>
              {item}
            </SelectItem>
          ))}
        </SelectContent>
      </Select>
    </div>
  </div>
);

export default Example;

API Reference

Select

SelectProps · components/Select/Select.types.ts
PropTypeDefault
resetTostring""

SelectGroup

SelectGroupProps · takes the props of Radix Select.Group

SelectValue

SelectValueProps · takes the props of Radix Select.Value

SelectTrigger

SelectTriggerProps · also takes the props of Radix Select.Trigger
PropTypeDefault
appearanceSelectTriggerAppearance"solid" | "soft" | "outline" | "transparent""solid"
sizeSelectTriggerSize"sm" | "base" | "lg""base"
borderRadiusSelectTriggerBorderRadius"none" | "xs" | "sm" | "base" | "lg" | "xl" | "full""base"
clearableboolean-
errorReactNode-

SelectContent

SelectContentProps · also takes the props of Radix Select.Content
PropTypeDefault
position"item-aligned" | "popper""popper"
sideOffsetnumber8

SelectLabel

SelectLabelProps · takes the props of Radix Select.Label

SelectItem

SelectItemProps · takes the props of Radix Select.Item

SelectSeparator

SelectSeparatorProps · takes the props of Radix Select.Separator

It also takes the props of Radix Select.Root.