Skip to Content
Zuri
Components

Select

A native select with a custom chevron and an invalid state.

Live preview
Theme
Preview width

Use Select to pick one option from a list. It wraps the browser's own <select>, so mobile users get the platform picker. If you need search or custom option rendering, that is a combobox, which is a separate component.

Looking for a dropdown that is not the browser's own menu? See the Picker: the same look on every device, with search and groups.

Installation

pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/select.json

Usage

import { Field } from "@/components/ui/field";
import { Select } from "@/components/ui/select";

<Field label="Country">
  {(control) => (
    <Select name="country" {...control}>
      <option value="tz">Tanzania</option>
      <option value="ke">Kenya</option>
    </Select>
  )}
</Field>

Variants, sizes and states

Live preview
Theme
Preview width

The glass variant blurs whatever is behind the closed control, so it needs a colourful backdrop. The open list is drawn by the browser and is not glass.

Props

Select extends all native <select> props and spreads them onto the element, including ref (React 19). Pass <option> and <optgroup> as children.

Props
PropTypeDefaultDescription
variant"default" | "glass""default"Visual style.
size"sm" | "md" | "lg""md"Minimum heights of 32, 40 and 48 pixels. This replaces the native numeric size attribute.
invalidboolean–Sets aria-invalid and a danger border. Field sets this for you.
classNamestring–Merged onto the select; yours win on conflicts.

Accessibility

  • It is a native <select>: keyboard, type-ahead, screen reader announcements and form submission all come from the browser.
  • It needs a name: use Field or a Label.
  • The chevron is decorative and hidden from screen readers.

Tokens used

--background, --foreground, --muted-foreground, --control-border, --danger, --ring, --duration-base, --ease-out, and the glass variables.

Known limitations

  • The open list can't be styled with CSS, so it follows the operating system.
  • No multiple-select styling yet.
  • Glass text contrast has not been measured against worst-case backdrops.

Source

"use client";import { cva, type VariantProps } from "class-variance-authority";import { type ComponentProps, useState } from "react";import { cn } from "@/lib/utils";const selectVariants = cva(  "w-full min-w-0 cursor-pointer appearance-none border pe-9 text-foreground transition-[border-color,background-color] duration-[var(--duration-base)] ease-[var(--ease-out)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-danger aria-[invalid=true]:animate-[zuri-shake_var(--duration-slow)_var(--ease-out)] motion-reduce:animate-none motion-reduce:transition-none",  {    variants: {      variant: {        default: "border-control-border bg-background",        glass: "zuri-glass",      },      size: {        sm: "min-h-8 rounded-md ps-3 text-sm",        md: "min-h-10 rounded-md ps-3 text-sm",        lg: "min-h-12 rounded-lg ps-4 text-base",      },    },    defaultVariants: { variant: "default", size: "md" },  },);export interface SelectProps  extends Omit<ComponentProps<"select">, "size">,    VariantProps<typeof selectVariants> {  /** Marks the value as invalid for assistive technology and styles the border. */  invalid?: boolean;}/** * A native `<select>` with a custom chevron. The native control keeps the platform's picker, * which is the best experience on phones. Pair it with a label (see Field). */export function Select({  className,  variant,  size,  invalid,  children,  onPointerDown,  onKeyDown,  onBlur,  ...props}: SelectProps) {  // Browsers treat a mouse click on a <select> as keyboard-like focus and draw the focus ring,  // which looks like a stray black border. Remember that the mouse was used, and hide the ring  // until a key is pressed.  const [pointer, setPointer] = useState(false);  return (    <span className="relative inline-flex w-full">      <select        aria-invalid={invalid || props["aria-invalid"] || undefined}        data-pointer={pointer || undefined}        onPointerDown={(e) => {          onPointerDown?.(e);          setPointer(true);        }}        onKeyDown={(e) => {          onKeyDown?.(e);          setPointer(false);        }}        onBlur={(e) => {          onBlur?.(e);          setPointer(false);        }}        className={cn(          selectVariants({ variant, size }),          "data-[pointer]:focus-visible:outline-none",          className,        )}        {...props}      >        {children}      </select>      <svg        aria-hidden="true"        viewBox="0 0 16 16"        fill="none"        stroke="currentColor"        strokeWidth="2"        strokeLinecap="round"        strokeLinejoin="round"        className="pointer-events-none absolute end-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"      >        <path d="M4 6l4 4 4-4" />      </svg>    </span>  );}export { selectVariants };

On this page