DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Select

The Select component is a controlled component that can be used to select one option from a set. It can be used in a group with other selects to allow for multiple selections.

  • npm
  • source
  • recipe
  • Ark
import {
Select,
Option,
OptionGroup,
OptionGroupLabel,
createSelectCollection
} from '@cerberus/react'

Usage

The Select component is a controlled component that can be used to select one option from a set. It can be used in a group with other selects to allow for multiple selections.

Hades
Persephone
Zeus
Poseidon
Hera
Copy
import {
For,
Field,
Select,
Option,
createSelectCollection
} from '@cerberus/react'
import { Box } from 'styled-system/jsx'
function SelectBasicPreview() {
const collection = createSelectCollection([
{ label: 'Hades', value: 'hades' },
{ label: 'Persephone', value: 'persephone' },
{ label: 'Zeus', value: 'zeus', disabled: true },
{ label: 'Poseidon', value: 'poseidon' },
{ label: 'Hera', value: 'hera' },
])
return (
<Box w="1/2">
<Field label="Select Relative">
<Select collection={collection} placeholder="Choose option">
<For each={collection.items}>
{(item) => <Option key={item.value} item={item} />}
</For>
</Select>
</Field>
</Box>
)
}

Grouped Options

To group options, use the OptionGroup and OptionGroupLabel components.

The fam
Hades
Persephone
Zeus
Poseidon
Hera
Copy
import {
For,
Field,
Select,
Option,
OptionGroup,
OptionGroupLabel,
createSelectCollection
} from '@cerberus/react'
import { Box } from 'styled-system/jsx'
function GroupedOptionsDemo() {
const collection = createSelectCollection([
{ label: 'Hades', value: '1-hades' },
{ label: 'Persephone', value: '1-persephone' },
{ label: 'Zeus', value: '1-zeus', disabled: true },
{ label: 'Poseidon', value: '1-poseidon' },
{ label: 'Hera', value: '1-hera' },
])
return (
<Box w="1/2">
<Field label="Select Relative">
<Select collection={collection} placeholder="Choose option">
<OptionGroup>
<OptionGroupLabel>The fam</OptionGroupLabel>
<For each={collection.items}>
{(item) => <Option key={item.value} item={item} />}
</For>
</OptionGroup>
</Select>
</Field>
</Box>
)
}

With Dialog

Some heading

This is a description for the dialog. You can use this space to provide more context or instructions for the user.
Hades
Persephone
Zeus
Poseidon
Hera
Copy
Select with Dialog Demo
'use client'
import {
Dialog,
DialogCloseIconTrigger,
DialogDescription,
DialogHeading,
DialogProvider,
DialogTrigger,
} from '@cerberus/react'
import { Box, VStack } from 'styled-system/jsx'
import { SelectBasicPreview } from './select-preview'
export function SelectWithDialogDemo() {
return (
<DialogProvider>
<DialogTrigger>Open Select Dialog</DialogTrigger>
<Dialog>
<VStack alignItems="flex-start" gap="lg" w="full">
<DialogCloseIconTrigger />
<DialogHeading>Some heading</DialogHeading>
<DialogDescription>
This is a description for the dialog. You can use this space to
provide more context or instructions for the user.
</DialogDescription>
<Box w="full">
<SelectBasicPreview />
</Box>
</VStack>
</Dialog>
</DialogProvider>
)
}

Primitives

You can utilize the primitive components or the css prop to customize the select.

ComponentDescription
SelectRootThe context provider for the Select family
SelectLabelThe label that appears above the select input
SelectControlThe wrapper to the select trigger that opens the dropdown
SelectTriggerhe trigger that opens the dropdown
SelectValueTextThe text that appears in the trigger
SelectIndicatorThe indicator that appears in the trigger
SelectClearTriggerThe trigger that clears the selected value
SelectPositionerThe wrapper that positions the dropdown
SelectContentThe content of the dropdown (i.e. the container itself)
SelectItemGroupThe group of options in the dropdown
SelectItemGroupLabelThe label for the group of options
SelectItemThe option in the dropdown
SelectItemTextThe text label of the option
SelectItemIndicatorThe indicator shown when the option is selected
SelectHiddenInputThe native select for the select group.
The fam
Hades
✓
Persephone
✓
Zeus
✓
Poseidon
✓
Hera
✓
Copy
Custom Select Demo
function SelectCustomPreview() {
const collection = createSelectCollection([
{ label: 'Hades', value: '1-hades' },
{ label: 'Persephone', value: '1-persephone' },
{ label: 'Zeus', value: '1-zeus', disabled: true },
{ label: 'Poseidon', value: '1-poseidon' },
{ label: 'Hera', value: '1-hera' },
])
return (
<Box w="1/2">
<SelectParts.Root collection={collection}>
<SelectParts.Label
css={{
paddingBlock: 2,
textStyle: 'body-sm',
textTransform: 'uppercase',
}}
>
Select a custom relative
</SelectParts.Label>
<SelectParts.Control>
<SelectParts.Trigger
className={cx(
css({
bgColor: 'black',
color: 'danger.surface.initial',
paddingInline: 4,
paddingBlock: 3,
_hover: {
bgColor: 'danger.surface.initial',
color: 'white',
},
}),
hstack({
justify: 'space-between',
w: 'full',
}),
)}
>
<SelectParts.ValueText placeholder="Choose a custom option" />
<SelectParts.Indicator
css={{
transitionProperty: 'transform',
transitionDuration: 'fast',
_open: {
transform: 'rotate(180deg)',
},
}}
>
<ChevronDownOutline />
</SelectParts.Indicator>
</SelectParts.Trigger>
<SelectParts.ClearTrigger>Clear</SelectParts.ClearTrigger>
</SelectParts.Control>
<Portal>
<SelectParts.Positioner css={{ w: 'var(--reference-width)' }}>
<SelectParts.Content
css={{
bgColor: 'danger.surface.initial',
p: 4,
}}
>
<SelectParts.ItemGroup>
<SelectParts.ItemGroupLabel
css={css({
fontWeight: 'bold',
textStyle: 'label-sm',
textTransform: 'uppercase',
})}
>
The fam
</SelectParts.ItemGroupLabel>
<For each={collection.items}>
{(item, idx) => (
<SelectParts.Item key={item.value} item={item}>
<SelectParts.ItemText
css={{
color: 'white',
display: 'inline-block',
}}
style={{
paddingInlineStart: `calc(16px * ${idx})`,
}}
>
{item.label}
</SelectParts.ItemText>
<SelectParts.ItemIndicator>✓</SelectParts.ItemIndicator>
</SelectParts.Item>
)}
</For>
</SelectParts.ItemGroup>
</SelectParts.Content>
</SelectParts.Positioner>
</Portal>
</SelectParts.Root>
</Box>
)
}

API

Select

The Select component is an abstraction of our primitives and accepts the following props:

NameDefaultDescription
placeholderThe placeholder to show in the select trigger.
size'md'The size of the select.
collectionThe collection of options to show in the dropdown.

The Select component also accepts all the props of the SelectRoot primitive props

Option

The Option component is an abstraction of our primitives and accepts the following props:

NameDefaultDescription
itemThe item to show in the dropdown. SelectCollectionItem

The Option component also accepts all the props of the SelectItem primitive props

OptionGroup

The OptionGroup component is an abstraction of our primitives and accepts the same props as the SelectItemGroup primitive.

OptionGroupLabel

The OptionGroupLabel component is an abstraction of our primitives and accepts the same props as the SelectItemGroupLabel primitive.

createSelectCollection

The createSelectCollection function is a utility function that creates a collection of options for the Select component.

export function createSelectCollection(
collection: SelectCollectionItem[],
): ListCollection<SelectCollectionItem> {
return createListCollection({
items: collection,
})
}

Parts

The SelectParts API is an Object containing the full family of components.

Note

It is best to only use the SelectParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe SelectRoot component which is the Provider for the family.
LabelThe SelectLabel component which displays the label and "required" notice.
ControlThe SelectControl component which is the visual field.
TriggerThe SelectTrigger component which is the trigger for the dropdown.
ClearTriggerThe SelectClearTrigger component which is the trigger to clear the selected value.
ValueTextThe SelectValueText component which displays the selected value.
IndicatorThe SelectIndicator component which displays the trigger indicator.
PositionerThe SelectPositioner component which is controls the positioning for the dropdown.
ContentThe SelectContent component which is the dropdown itself.
ItemGroupThe SelectItemGroup component which is the group of options in the dropdown.
ItemGroupLabelThe SelectItemGroupLabel component which is the label for the group of options.
ItemThe SelectItem component which is the option in the dropdown.
ItemTextThe SelectItemText component which is the text label of the option.
ItemIndicatorThe SelectItemIndicator component which displays based on the checked state.
HiddenInputThe SelectHiddenInput component which displays the native input.

On this page

  • Edit this page on Github
Cerberus Design System | Docs