Select
A select picks one value from a short list that opens in a popup.
When to use
Section titled “When to use”- Use it for 4 to 15 options.
- Use radio buttons for 2 or 3 options, so all are visible at once.
- Use a Combobox when the list is long or people search it.
Anatomy
Section titled “Anatomy”- 1Trigger showing the value
- 2Chevron
- 3List of options
- 4Selected option with a check
A trigger on radius-md showing the chosen value or a placeholder, and a popup on popover with radius-lg and elevation from shadow-md. The popup renders outside the page flow, so it is never clipped by a card.
Variants
Section titled “Variants”There is one style, in two trigger sizes: default and sm.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
items |
children (SelectItem) |
options |
list | none | The options. In React, Base UI needs items on the root. |
value / defaultValue |
v-model / default-value |
initialValue |
string | none | The chosen value. |
onValueChange |
@update:model-value |
onChanged |
function | none | Runs when the value changes. |
placeholder item (value: null) |
placeholder on SelectValue |
placeholder |
text | none | Shown before a choice. |
disabled |
disabled |
enabled: false |
boolean | false |
Blocks opening. |
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue,} from "@/components/ui/select"
const products = [ { label: "Pilih produk", value: null }, { label: "Loka Musik", value: "lokamusik" }, { label: "Cover Clearance", value: "coverclearance" }, { label: "Lokasign", value: "lokasign" }, { label: "My Loka Link", value: "mylokalink" },]
export default function SelectDemo() { return ( <Select items={products}> <SelectTrigger className="w-56" aria-label="Produk"> <SelectValue /> </SelectTrigger> <SelectContent> <SelectGroup> {products .filter((p) => p.value !== null) .map((p) => ( <SelectItem key={p.value} value={p.value}> {p.label} </SelectItem> ))} </SelectGroup> </SelectContent> </Select> )}<script setup lang="ts">import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue,} from "@/components/ui/select"
const products = [ { label: "Loka Musik", value: "lokamusik" }, { label: "Cover Clearance", value: "coverclearance" }, { label: "Lokasign", value: "lokasign" }, { label: "My Loka Link", value: "mylokalink" },]</script>
<template> <Select> <SelectTrigger class="w-56" aria-label="Produk"> <SelectValue placeholder="Pilih produk" /> </SelectTrigger> <SelectContent> <SelectGroup> <SelectItem v-for="p in products" :key="p.value" :value="p.value"> {{ p.label }} </SelectItem> </SelectGroup> </SelectContent> </Select></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
const products = { 'lokamusik': 'Loka Musik', 'coverclearance': 'Cover Clearance', 'lokasign': 'Lokasign', 'mylokalink': 'My Loka Link',};
class SelectDemo extends StatelessWidget { const SelectDemo({super.key});
@override Widget build(BuildContext context) { return ConstrainedBox( constraints: const BoxConstraints(minWidth: 224), child: ShadSelect<String>( placeholder: const Text('Pilih produk'), options: products.entries .map((e) => ShadOption(value: e.key, child: Text(e.value))) .toList(), selectedOptionBuilder: (context, value) => Text(products[value]!), onChanged: (value) {}, ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/select.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/select.jsonAccessibility
Section titled “Accessibility”- The trigger has
role="combobox"and opens with Enter, Space or the arrow keys. - Arrow keys move through options; typing jumps to a matching option; Escape closes.
- Give the trigger a label, or an
aria-labelwhen no visible label fits.
