Select
The single-choice select. Note that onValueChange can hand you null.
Pick one option from a list. When there are many options and you want search, use
SearchableSelect; for a handful shown side by side,
SegmentedControl.
export const client = "only";
import { useState } from "react";
import {
Select,
SelectTrigger,
SelectValue,
SelectContent,
SelectGroup,
SelectLabel,
SelectItem,
SelectSeparator,
} from "@squadbase/vantage/ui";
const regions = {
hokkaido: "北海道",
kanto: "関東",
kansai: "関西",
kyushu: "九州",
};
export default function Example() {
const [region, setRegion] = useState("kanto");
return (
<Select
items={regions}
value={region}
onValueChange={(value) => value !== null && setRegion(value)}
>
<SelectTrigger className="w-56">
<SelectValue placeholder="地域を選ぶ" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>東日本</SelectLabel>
<SelectItem value="hokkaido">北海道</SelectItem>
<SelectItem value="kanto">関東</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup>
<SelectLabel>西日本</SelectLabel>
<SelectItem value="kansai">関西</SelectItem>
<SelectItem value="kyushu">九州</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
);
}
import {
Select,
SelectTrigger,
SelectValue,
SelectContent,
SelectGroup,
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
} from "@squadbase/vantage/ui";
Parts
| Part | Role |
|---|---|
Select |
The state: value / defaultValue / onValueChange / items |
SelectTrigger |
The closed state. size: default | sm |
SelectValue |
What’s selected; placeholder covers “nothing yet” |
SelectContent |
The open list |
SelectGroup + SelectLabel |
A group with a heading |
SelectItem |
One option; value is required |
SelectContent opens over the trigger with the selected item aligned to it. For a plain dropdown
below the trigger, pass alignItemWithTrigger={false}.