Select

A dropdown component that presents a list of selectable options when triggered by a button.

Usage

import {
  Select,
  SelectContent,
  SelectGroup,
  SelectIcon,
  SelectItem,
  SelectPortal,
  SelectTrigger,
  SelectValue,
} from "@lemonsqueezy/wedges";
<Select>
  <SelectTrigger />
    <SelectContent>
      <SelectGroup>
        <SelectItem value="item-1">Item 1</SelectItem>
        <SelectItem value="item-2">Item 2</SelectItem>
        <SelectItem value="item-3">Item 3</SelectItem>
      </SelectGroup>
    </SelectContent>
</Select>

You can use SelectPortal to render the content in a different location in the DOM. See API Reference for details.

<Select>
  <SelectTrigger />
  <SelectPortal>
      <SelectContent>
        <SelectGroup>
          <SelectItem value="item-1">Item 1</SelectItem>
          <SelectItem value="item-2">Item 2</SelectItem>
          <SelectItem value="item-3">Item 3</SelectItem>
        </SelectGroup>
      </SelectContent>
    </SelectPortal>
</Select>

API Reference

Select

Contains all the parts of a select. A styled wrapper around Radix Select.Root primitive with additional features.

PropValueDefault
label
ReactNode
/
description
ReactNode
/
tooltip
ReactNode
/
helperText
ReactNode
/
defaultOpen
boolean
/
defaultValue
string
/
dir
enum
/
disabled
boolean
/
name
string
/
onOpenChange
function
/
onValueChange
function
/
open
boolean
/
reqiured
boolean
/
value
string
/

SelectTrigger

The button that toggles the select. The SelectContent component is rendered when the trigger is clicked.

PropValueDefault
asChild
boolean
false
Data attributeValue
[data-disabled]
Present when disabled
[data-placeholder]
Present when has placeholder
[data-state]
"open" | "closed"

SelectValue

The part that reflects the selected value. By default the selected item’s text will be rendered. if you require more control, you can instead control the select and pass your own children. It should not be styled to ensure correct positioning. An optional placeholder prop is also available for when the select has no value.

PropValueDefault
asChild
boolean
false
placeholder
ReactNode
/

SelectIcon

A small icon often displayed next to the value as a visual affordance for the fact it can be open. By default renders a chevron icon pointed down or up depending on the open state, but you can use your own icon via asChild or use children.

PropValueDefault
asChild
boolean
false

SelectPortal

When used, portals the content part into the body. By default it appends content to the body, but you can specify a custom container.

PropValueDefault
container
HTMLElement
document.body

SelectContent

The component that pops out when the select is open. A styled wrapper around Radix Select.Content primitive with additional features.

PropValueDefault
asChild
boolean
false
onCloseAutoFocus
function
/
onEscapeKeyDown
function
/
onPointerDownOutside
function
/
position
enum
popper
side
enum
"bottom"
sideOffset
number
8
align
enum
"start"
alignOffset
number
0
avoidCollisions
boolean
true
collisionBoundary
Boundary
[]
collisionPadding
number | Padding
10
sticky
enum
"partial"
hideWhenDetached
boolean
false
showScrollButtons
boolean
false
Data attributeValue
[data-align]
"start" | "end" | "center"
[data-side]
"left" | "right" | "bottom" | "top"
[data-state]
"open" | "closed"

SelectItem

The component that contains the select items.

By default SelectItemText and SelectItemIndicator are rendered inside the SelectItem component. You can use your own components if you need to customize it via children.

PropValueDefault
asChild
boolean
false
disabled
boolean
false
textValue
string
/
value
string
/
Data attributeValue
[data-disabled]
Present when disabled
[data-highlighted]
Present when highlighted
[data-state]
"checked" | "unchecked"

SelectItemText

The textual part of the item. It should only contain the text you want to see in the trigger when that item is selected. It should not be styled to ensure correct positioning.

PropValueDefault
asChild
boolean
false

SelectItemIndicator

Renders when the item is selected. You can style this element directly, or you can use it as a wrapper to put an icon into, or both. By default it renders a checkmark icon.

PropValueDefault
asChild
boolean
false

SelectGroup

PropValueDefault
asChild
boolean
false

SelectLabel

Used to render the label of a group. It won’t be focusable using arrow keys.

PropValueDefault
asChild
boolean
false

SelectSeparator

Used to visually separate items in the select.

PropValueDefault
asChild
boolean
false

Accessibility

The Select component supports all accessibility features of the Radix Select primitive.

Examples

The following example shows how to add icons to the SelectItem and style them with Tailwind CSS. Icons are added using a custom DotIcon component, which is placed inside each SelectItem alongside the text. Tailwind classes like flex and gap-1 are used to align and space the icons and text properly.

Each icon is styled with custom colors to represent different statuses.

Next example demonstrates how to structure your items, with groups separators, and labels. The SelectContent component in this example uses a different content position - item-aligned.

Helper text
Edit this page