Select
Native select with the same field finish as the input, a chevron over the right edge and an optional disabled placeholder option.
pnpm dlx shadcn@latest add @haze/select---
import { ChevronDown } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Option {
value: string;
label: string;
disabled?: boolean;
}
interface Props {
id: string;
name?: string;
options: Option[];
/** The selected value. */
value?: string;
/** Renders a disabled, empty first option that shows until the user chooses. */
placeholder?: string;
required?: boolean;
class?: string;
/** Any other select attribute, for example disabled, aria-describedby or aria-invalid. */
[key: string]: unknown;
}
const { id, name = id, options, value, placeholder, required, class: className, ...rest } = Astro.props;
---
<div class={cn("relative h-10 w-full min-w-0 rounded-lg", className)}>
<select
id={id}
name={name}
required={required}
class={cn(
"peer h-full w-full min-w-0 appearance-none rounded-[inherit] [&::picker-icon]:hidden border border-frame bg-field pr-9 pl-3 text-[0.8125rem] tracking-[-0.01em] text-foreground",
"transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent",
"focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden",
"disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:border-frame disabled:hover:bg-field aria-invalid:border-destructive! aria-invalid:focus-visible:ring-destructive/24",
"[&>option]:bg-popover [&>option]:text-popover-foreground",
)}
{...rest}
>
{placeholder && <option value="" disabled selected={!value}>{placeholder}</option>}
{options.map((option) => <option value={option.value} disabled={option.disabled} selected={option.value === value}>{option.label}</option>)}
</select>
<ChevronDown class="pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 text-muted-foreground peer-disabled:opacity-50" aria-hidden="true" />
</div>When to use
- Choosing one value from a list of roughly 4 to 15 fixed options
- Region, country, time zone or billing cycle pickers in forms
- Mobile-first forms where the operating system's own picker is the best experience
When not to use
- Two or three options that fit on screen; use radio-group or toggle-group
- Options that need icons, search or rich content
Installation
Add the Haze registry to components.json once, then install Select with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/selectnpx shadcn@latest add @haze/selectyarn dlx shadcn@latest add @haze/selectbunx --bun shadcn@latest add @haze/selectFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Element id; reference it from a label or Field. |
| name | string | id | Form field name. |
| options* | { value: string; label: string; disabled?: boolean }[] | – | The choices, in display order. |
| value | string | – | Value of the option that is selected on load. |
| placeholder | string | – | Adds a disabled, empty first option with this text; it is selected only when no value is given. |
| required | boolean | – | Marks the field required. |
| class | string | – | Extra classes on the select element. |
| ...rest | attributes | – | Any other select attribute: disabled, aria-invalid, aria-describedby. |
Keyboard interactions
- Arrow UpArrow Down
- Changes the selected option
- AltArrow Down or Space
- Opens the option list
- Type a letter
- Jumps to the next option starting with it
Accessibility
- The chevron is aria-hidden and ignores the pointer, so the whole box opens the native picker and screen readers announce a plain select.
- Options use the popover colors so the native list is dark on Windows.
- The placeholder option is disabled with an empty value, so a required select cannot be submitted without a real choice.
- The component renders no label; pair it with Field or a label whose for matches the id.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Select" with `npx shadcn@latest add @haze/select`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Select from "@/components/haze/ui/select.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/select.md
Customize with real content
Adapt the Haze select ui for our product. Replace the demo values of these props with our real content: id, name, options, value, placeholder, required, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The chevron is aria-hidden and ignores the pointer, so the whole box opens the native picker and screen readers announce a plain select. Options use the popover colors so the native list is dark on Windows. The placeholder option is disabled with an empty value, so a required select cannot be submitted without a real choice. The component renders no label; pair it with Field or a label whose for matches the id. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using select, check it fits: use it when choosing one value from a list of roughly 4 to 15 fixed options; region, country, time zone or billing cycle pickers in forms; mobile-first forms where the operating system's own picker is the best experience. Avoid it when two or three options that fit on screen; use radio-group or toggle-group; options that need icons, search or rich content. Alternatives: @haze/radio-group, @haze/toggle-group, @haze/dropdown-menu.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.