Skip to content
Unkey Design Docs
Esc
↑↓navigate↵open⌘Jpreview
On this page

Select

A dropdown for picking one value from a short list.

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

const environments = [
  { value: "production", label: "production" },
  { value: "preview", label: "preview" },
];

export default function SelectSizes() {
  return (
    <div className="flex w-56 flex-col gap-3">
      {(["md", "sm"] as const).map((size) => (
        <Select key={size} defaultValue="production" items={environments}>
          <SelectTrigger size={size} aria-label={`Environment, ${size}`}>
            <SelectValue />
          </SelectTrigger>
          <SelectContent>
            {environments.map((env) => (
              <SelectItem key={env.value} value={env.value}>
                {env.label}
              </SelectItem>
            ))}
          </SelectContent>
        </Select>
      ))}
    </div>
  );
}

Sizes

  • md is the default. Use it in forms.
  • sm fits dense rows, toolbars and slide panels. It is 32px tall with a smaller chevron.

Set the size on SelectTrigger. SelectContent already sits above slide panels and dialogs, so do not add a z-* class to it.

Long lists

Pass maxRows to SelectContent when the list is long or sits above other fields. The list stops at that many rows and scrolls. Use 5 in forms and slide panels.

FormSelect

FormSelect wraps the four Select parts with a label, a description and an error. Use it before you build a Select by hand.

import { FormSelect } from "@unkey/ui";
import { useState } from "react";

const fields = [
  { value: "path", label: "Path" },
  { value: "method", label: "Method" },
] as const;

const methods = ["GET", "POST", "PUT", "DELETE"].map((m) => ({ value: m, label: m }));

export default function FormSelectInline() {
  const [field, setField] = useState<(typeof fields)[number]["value"]>("path");
  const [picked, setPicked] = useState<string[]>(["GET"]);
  return (
    <div className="flex w-96 items-center gap-2">
      <FormSelect
        size="sm"
        aria-label="Condition field"
        options={fields}
        value={field}
        onValueChange={setField}
        className="w-32 shrink-0"
      />
      <FormSelect
        multiple
        size="sm"
        aria-label="Methods"
        placeholder="Pick methods"
        options={methods}
        value={picked}
        onValueChange={setPicked}
        className="min-w-0 flex-1"
      />
    </div>
  );
}
  • Without label, give it an aria-label. It then fits inline in a row.
  • size="sm" uses the small trigger.
  • multiple takes and returns an array of values.
  • Pass value={null} with a placeholder when the user must make a choice. The placeholder shows in placeholder gray.
  • The value type follows the options, so onValueChange needs no narrowing.
  • Set disabled on an option to show it but block its selection.

Warning

Set variant="warning" when the value is allowed but risky. The trigger border and the description turn amber, and the description gets a warning icon. An error still wins over the warning.

import { FormSelect } from "@unkey/ui";
import { useState } from "react";

const durations = [
  { value: "30m", label: "30 minutes" },
  { value: "24h", label: "24 hours" },
] as const;

export default function FormSelectWarning() {
  const [value, setValue] = useState<(typeof durations)[number]["value"]>("30m");
  const soon = value === "30m";
  return (
    <div className="w-96">
      <FormSelect
        label="Expiration"
        options={durations}
        value={value}
        onValueChange={setValue}
        variant={soon ? "warning" : undefined}
        description={
          soon
            ? "This key is disabled in 30 minutes. That is 1 hour or less from now."
            : "This key is disabled in 24 hours."
        }
      />
    </div>
  );
}

Label action

Pass labelAction to put a small control, such as a ghost Remove button, at the right of the label row. The row keeps its height. labelAction needs a label.

import { Button, FormSelect } from "@unkey/ui";
import { useState } from "react";

const regions = [
  { value: "us-east-1", label: "us-east-1" },
  { value: "eu-central-1", label: "eu-central-1" },
];

export default function FormSelectLabelAction() {
  const [region, setRegion] = useState("us-east-1");
  return (
    <div className="w-80">
      <FormSelect
        label="Fallback region"
        labelAction={
          <Button type="button" variant="ghost" size="sm">
            Remove
          </Button>
        }
        size="sm"
        options={regions}
        value={region}
        onValueChange={setRegion}
      />
    </div>
  );
}