Skip to content
Drivn logoDrivn

Select

Custom select dropdown with dot notation and composable options.

Preview

Installation

npx drivn add select

Usage

1import { useState } from "react"
2import { Select } from "@/components/ui/select"
3
4const options = [
5 { label: "React", value: "react" },
6 { label: "Vue", value: "vue" },
7 { label: "Svelte", value: "svelte" },
8]
9
10export default function Page() {
11 const [value, setValue] = useState("")
12
13 return (
14 <Select value={value} onChange={setValue}>
15 <Select.Trigger placeholder="Pick a framework">
16 {options.find(o => o.value === value)?.label}
17 </Select.Trigger>
18 <Select.Menu>
19 {options.map(o => (
20 <Select.Option key={o.value} value={o.value}>
21 {o.label}
22 </Select.Option>
23 ))}
24 </Select.Menu>
25 </Select>
26 )
27}

API Reference

Select

PropTypeDefaultDescription
valuestringCurrently selected value
onChange(value: string) => voidCallback fired when the selected value changes
classNamestringAdditional CSS classes to apply
childrenReactNodeSelect sub-components (Trigger, Menu, Option)

Select.Option

PropTypeDefaultDescription
valuestringThe value associated with this option
childrenReactNodeLabel content for the option