'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectBasics = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Usage
import { Select } from '@fidely-ui/react'<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
<Select.Indicator>
<BiChevronDown />
</Select.Indicator>
</Select.Trigger>
<Select.ClearTrigger>Clear</Select.ClearTrigger>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
<Select.ItemGroup>
<Select.ItemGroupLabel>Frameworks</Select.ItemGroupLabel>
<Select.Item key={item} item={item}>
<Select.ItemText>Hello</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
</Select.ItemGroup>
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>Examples
Variants
Use the variant prop to change the appearance of the Select component.
'use client'
import { createListCollection, Portal, Select, Stack } from '@fidely-ui/react'
export const SelectVariant = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
const variants = ['outline', 'subtle'] as const
return (
<Stack gap={3}>
{variants.map((variant) => (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
variant={variant}
key={variant}
>
<Select.Label>{variant}</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
))}
</Stack>
)
}
Sizes
Use the size prop to adjust the size of the Select component.
'use client'
import { createListCollection, Portal, Select, Stack } from '@fidely-ui/react'
export const SelectSize = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
const sizes = ['xs', 'sm', 'md', 'lg'] as const
return (
<Stack gap={3}>
{sizes.map((size) => (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
size={size}
key={size}
>
<Select.Label>{size}</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
))}
</Stack>
)
}
Option Group
Use the Select.ItemGroup component to group related select options.
'use client'
import { Portal, Select } from '@fidely-ui/react'
import { createListCollection } from '@fidely-ui/react/collection'
export const SelectGroup = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
<Select.ItemGroup>
<Select.ItemGroupLabel>Frameworks</Select.ItemGroupLabel>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.ItemGroup>
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Controlled
Use the value and onValueChange props to control the select component.
'use client'
import { useState } from 'react'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectControlled = () => {
const [value, setValue] = useState<string[]>([])
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
value={value}
onValueChange={(e) => setValue(e.value)}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Disabled
Use the value and onValueChange props to control the select component.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectDisabled = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
disabled
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Multiple
Use the multiple prop to allow multiple selections.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectMultiple = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
multiple
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Icon
Render your icon with Select.Indicator or Select.ClearTriggerr to use your custom icon.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
import { PiCaretUpDownLight } from 'react-icons/pi'
export const SelectIcon = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator>
<PiCaretUpDownLight size={20} />
</Select.Indicator>
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Invalid
Pass the invalid prop to the Select.Root.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectInvalid = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
invalid
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Positioning
Use the positioning prop to control the underlying floating-ui options of the select component.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectPositioning = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ placement: 'bottom', flip: false }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
ClearTrigger
Render the Select.ClearTrigger component to show a clear button. Clicking the clear button will clear the selected value.
'use client'
import { createListCollection, Portal, Select } from '@fidely-ui/react'
export const SelectTrigger = () => {
const collection = createListCollection({
items: ['React', 'Solid', 'Vue', 'Svelte'],
})
return (
<Select.Root
collection={collection}
positioning={{ sameWidth: true }}
maxW={'350px'}
>
<Select.Label>Framework</Select.Label>
<Select.Control>
<Select.Trigger>
<Select.ValueText placeholder="Select a Framework" />
</Select.Trigger>
<Select.IndicatorGroup>
<Select.ClearTrigger />
<Select.Indicator />
</Select.IndicatorGroup>
</Select.Control>
<Portal>
<Select.Positioner>
<Select.Content>
{collection.items.map((item) => (
<Select.Item key={item} item={item}>
<Select.ItemText>{item}</Select.ItemText>
<Select.ItemIndicator>✓</Select.ItemIndicator>
</Select.Item>
))}
</Select.Content>
</Select.Positioner>
</Portal>
<Select.HiddenSelect />
</Select.Root>
)
}
Props
Root
| Prop | Type | Default | Description |
|---|---|---|---|
as | React.ElementType | — | The underlying element to render. |
asChild | boolean | — | Uses the provided child element as the rendered element, merging its props and behavior. |
autoFocus | boolean | — | Whether to autofocus the input on mount. |
closeOnSelect | boolean | — | Whether the select should close after an item is selected. |
collection | ListCollection<T> | — | The collection of items. |
defaultHighlightedValue | string | — | The initial value of the highlighted item when opened. |
defaultOpen | boolean | — | Whether the select is open by default. |
defaultValue | string[] | [] | The initial default value of the select when rendered. |
disabled | boolean | — | Whether the select is disabled. |
form | string | — | The associated form of the select. |
highlightedValue | string | — | The controlled highlighted item value. |
id | string | — | The id of the select root element. |
invalid | boolean | — | Whether the select is in an invalid state. Adds data-invalid and aria-invalid. |
loop | boolean | true | Whether navigation wraps around when reaching the first or last item. |
multiple | boolean | false | Whether multiple values can be selected. |
name | string | — | The name of the select when used in a form. |
onHighlightChange | (details: HighlightChangeDetails) => void | — | Called when the highlighted option changes. |
onOpenChange | (details: OpenChangeDetails) => void | — | Called when the select’s open/close state changes. |
onValueChange | (details: ValueChangeDetails) => void | — | Called when the selected value changes. |
open | boolean | — | Controls the open state of the select. |
openOnClick | boolean | true | Whether clicking the trigger opens the select. |
positioning | Positioning | — | The positioning options for the select dropdown. |
preventScroll | boolean | false | Prevents scroll locking when open. |
required | boolean | — | Whether selection is required before form submission. |
sameWidth | boolean | true | Whether the dropdown should match the trigger width. |
value | string[] | — | The controlled value of the select. |
width | string | number | — | The width of the select trigger. |