Select component allows users to choose from a list of options.
Default
Compound component with trigger and dropdown. Use SelectTrigger to create the button, SelectContainer for the dropdown, and SelectOption for each option.
1import {
2 Select,
3 SelectContainer,
4 SelectOption,
5 SelectTrigger,
6} from '@devup-ui/components'
7
8export default function Default() {
9 return (
10 <Select>
11 <SelectTrigger>Select an option</SelectTrigger>
12 <SelectContainer>
13 <SelectOption value="option1">Option 1</SelectOption>
14 <SelectOption value="option2">Option 2</SelectOption>
15 <SelectOption value="option3">Option 3</SelectOption>
16 </SelectContainer>
17 </Select>
18 )
19}
201import {
2 Select,
3 SelectContainer,
4 SelectOption,
5 SelectTrigger,
6} from '@devup-ui/components'
7
8export default function Default() {
9 return (
10 <Select>
11 <SelectTrigger>Select an option</SelectTrigger>
12 <SelectContainer>
13 <SelectOption value="option1">Option 1</SelectOption>
14 <SelectOption value="option2">Option 2</SelectOption>
15 <SelectOption value="option3">Option 3</SelectOption>
16 </SelectContainer>
17 </Select>
18 )
19}
20Radio Type
Use type="radio" for single selection mode. The selected option is highlighted with a check icon, and the dropdown closes after selection.
1'use client'
2
3import {
4 Select,
5 SelectContainer,
6 SelectOption,
7 SelectTrigger,
8} from '@devup-ui/components'
9import { useState } from 'react'
10
11export default function Radio() {
12 const [value, setValue] = useState('')
13
14 return (
15 <Select onChange={setValue} type="radio" value={value}>
16 <SelectTrigger>{value || 'Select an option'}</SelectTrigger>
17 <SelectContainer>
18 <SelectOption value="option1">Option 1</SelectOption>
19 <SelectOption value="option2">Option 2</SelectOption>
20 <SelectOption value="option3">Option 3</SelectOption>
21 </SelectContainer>
22 </Select>
23 )
24}
251'use client'
2
3import {
4 Select,
5 SelectContainer,
6 SelectOption,
7 SelectTrigger,
8} from '@devup-ui/components'
9import { useState } from 'react'
10
11export default function Radio() {
12 const [value, setValue] = useState('')
13
14 return (
15 <Select onChange={setValue} type="radio" value={value}>
16 <SelectTrigger>{value || 'Select an option'}</SelectTrigger>
17 <SelectContainer>
18 <SelectOption value="option1">Option 1</SelectOption>
19 <SelectOption value="option2">Option 2</SelectOption>
20 <SelectOption value="option3">Option 3</SelectOption>
21 </SelectContainer>
22 </Select>
23 )
24}
25Checkbox Type
Use type="checkbox" for multiple selection mode. Users can select multiple options, and use showConfirmButton on the container to add a confirm button.
1'use client'
2
3import {
4 Select,
5 SelectContainer,
6 SelectOption,
7 SelectTrigger,
8} from '@devup-ui/components'
9import { useState } from 'react'
10
11export default function Checkbox() {
12 const [value, setValue] = useState<string[]>([])
13
14 const handleChange = (nextValue: string) => {
15 if (value.includes(nextValue)) {
16 setValue(value.filter((v) => v !== nextValue))
17 } else {
18 setValue([...value, nextValue])
19 }
20 }
21
22 return (
23 <Select onChange={handleChange} type="checkbox" value={value}>
24 <SelectTrigger>
25 {value.length > 0 ? value.join(', ') : 'Select options'}
26 </SelectTrigger>
27 <SelectContainer showConfirmButton>
28 <SelectOption value="option1">Option 1</SelectOption>
29 <SelectOption value="option2">Option 2</SelectOption>
30 <SelectOption value="option3">Option 3</SelectOption>
31 </SelectContainer>
32 </Select>
33 )
34}
351'use client'
2
3import {
4 Select,
5 SelectContainer,
6 SelectOption,
7 SelectTrigger,
8} from '@devup-ui/components'
9import { useState } from 'react'
10
11export default function Checkbox() {
12 const [value, setValue] = useState<string[]>([])
13
14 const handleChange = (nextValue: string) => {
15 if (value.includes(nextValue)) {
16 setValue(value.filter((v) => v !== nextValue))
17 } else {
18 setValue([...value, nextValue])
19 }
20 }
21
22 return (
23 <Select onChange={handleChange} type="checkbox" value={value}>
24 <SelectTrigger>
25 {value.length > 0 ? value.join(', ') : 'Select options'}
26 </SelectTrigger>
27 <SelectContainer showConfirmButton>
28 <SelectOption value="option1">Option 1</SelectOption>
29 <SelectOption value="option2">Option 2</SelectOption>
30 <SelectOption value="option3">Option 3</SelectOption>
31 </SelectContainer>
32 </Select>
33 )
34}
35Options
Use the options prop as a shorthand to define options without compound components. Each option can have label, value, disabled, and onClick properties.
1import { Select } from '@devup-ui/components'
2
3export default function WithOptions() {
4 return (
5 <Select
6 options={[
7 { label: 'Option 1', value: 'option1' },
8 { label: 'Option 2', value: 'option2' },
9 { label: 'Option 3', value: 'option3', disabled: true },
10 ]}
11 >
12 Select with options prop
13 </Select>
14 )
15}
161import { Select } from '@devup-ui/components'
2
3export default function WithOptions() {
4 return (
5 <Select
6 options={[
7 { label: 'Option 1', value: 'option1' },
8 { label: 'Option 2', value: 'option2' },
9 { label: 'Option 3', value: 'option3', disabled: true },
10 ]}
11 >
12 Select with options prop
13 </Select>
14 )
15}
16The Select component is a compound component that consists of multiple parts.
The root component that provides context for the select.
| Prop | description | Type | Default |
|---|---|---|---|
| children | The select content (Trigger, Container, Options) |
| |
| value | The controlled value of the select |
|
|
| defaultValue | The default value of the select (uncontrolled) |
|
|
| onChange | Callback when the selected value changes |
|
|
| open | Whether the select dropdown is open (controlled) |
|
|
| defaultOpen | Whether the select dropdown is open by default |
|
|
| onOpenChange | Callback when the open state changes |
|
|
| type | The selection mode of the select |
|
|
| typography | Typography style key from the theme |
|
|
| options | Shorthand for defining options without using compound components |
|
|
| colors | Custom color variables for the select |
|
|
The button that triggers the dropdown to open/close.
| Prop | description | Type | Default |
|---|---|---|---|
| children | The trigger content |
| |
| asChild | Render as the child element instead of a Button |
|
|
The dropdown container that holds the options.
| Prop | description | Type | Default |
|---|---|---|---|
| children | The container content (Options) |
| |
| showConfirmButton | Whether to show a confirm button (for checkbox type) |
|
|
| confirmButtonText | Text for the confirm button |
|
|
| x | Horizontal offset for the dropdown position |
|
|
| y | Vertical offset for the dropdown position |
|
|
An individual option within the select dropdown.
| Prop | description | Type | Default |
|---|---|---|---|
| children | The option content |
| |
| value | The value of the option |
|
|
| disabled | Whether the option is disabled |
|
|
| showCheck | Whether to show a check icon when selected |
|
|
| onClick | Custom click handler for the option |
|
|
A visual divider between options.