PeakUI

Select

Selects one or more values from a collapsible listbox

Usage

import {Label, ListBox, Select} from "@peakui/react";

Anatomy

import {Description, Label, ListBox, Select} from "@peakui/react";

export default () => (
  <Select>
    <Label />
    <Select.Trigger>
      <Select.Value />
      <Select.ClearButton />
      <Select.Indicator />
    </Select.Trigger>
    <Description />
    <Select.Popover>
      <ListBox>
        <ListBox.Item>
          <ListBox.ItemIndicator />
        </ListBox.Item>
      </ListBox>
    </Select.Popover>
  </Select>
);

Examples

Variants

Full Width

With Description

Multiple Select

With Sections

With Disabled Options

With Clear Button

Composing Select.ClearButton also arms the trigger's Backspace/Delete clear shortcut, which is how keyboard and screen reader users clear; both paths call onClear.

Custom Indicator

Required

Custom Value

Custom Value Multiple

Controlled

Controlled Multiple

Controlled Open State

Asynchronous Loading

Disabled

Customization

Tailwind CSS

Global CSS

@layer components {
  .select {
    @apply flex flex-col gap-1;
  }

  .select__trigger {
    @apply rounded-lg border border-border bg-surface p-2;
  }

  .select__value {
    @apply text-current;
  }

  .select__indicator {
    @apply text-muted;
  }

  .select__popover {
    @apply rounded-lg border border-border bg-surface p-2;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Select component uses these CSS classes (view source styles):

Base & Element Classes

  • .select - Base select container
  • .select__trigger - The button that triggers the select
  • .select__value - The displayed value or placeholder
  • .select__clear-button - The optional clear control inside the trigger
  • .select__indicator - The dropdown indicator icon
  • .select__popover - The popover container

Variant Classes

  • .select--primary - Primary variant with shadow (default)
  • .select--secondary - Secondary variant without shadow, suitable for use in surfaces

Modifier Classes

  • .select--full-width - Takes the full width of the container
  • .select__trigger--full-width - Full width on the trigger itself

Slots

  • [data-slot="select"]
  • [data-slot="select-trigger"]
  • [data-slot="select-value"]
  • [data-slot="select-indicator"]
  • [data-slot="select-default-indicator"]
  • [data-slot="select-clear-button"]
  • [data-slot="select-clear-button-icon"]
  • [data-slot="select-popover"]

CSS Variables

VariablePurpose
--select-trigger-bgSecondary variant trigger background
--select-trigger-bg-hoverSecondary variant trigger background on hover
--select-trigger-bg-focusSecondary variant trigger background while focused

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered] on trigger
  • Focus: :focus-visible or [data-focus-visible] on trigger
  • Disabled: :disabled, [data-disabled] or [aria-disabled="true"] on trigger
  • Invalid: [data-invalid] or [aria-invalid="true"] on select
  • Placeholder: [data-placeholder] on value
  • Empty: [data-empty] on clear button
  • Open: [data-open] on indicator

API Reference

Select

PropTypeDefaultDescription
placeholderstring'Select an item'Temporary text that occupies the select when it is empty
selectionMode"single" | "multiple""single"Whether single or multiple selection is enabled
valueKey | Key[] | null-Current value (controlled)
defaultValueKey | Key[] | null-Default value (uncontrolled)
onChange(value: Key | Key[] | null) => void-Handler called when the value changes
onClear() => void-Handler called when the selection is cleared
isOpenboolean-Sets the open state of the menu (controlled)
defaultOpenboolean-Sets the default open state of the menu (uncontrolled)
onOpenChange(isOpen: boolean) => void-Handler called when the open state changes
itemsIterable<T>-Items for a dynamic collection, rendered by a function child of ListBox
disabledKeysIterable<Key>-Keys of disabled items
isDisabledboolean-Whether the select is disabled
isRequiredboolean-Whether user input is required
isInvalidboolean-Whether the select value is invalid
namestring-The name of the input, used when submitting an HTML form
autoCompletestring-Describes the type of autocomplete functionality
fullWidthbooleanfalseWhether the select should take full width of its container
variant"primary" | "secondary""primary"Visual variant of the component; secondary is the lower emphasis variant for surfaces
classNamestring | (values: SelectRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: SelectRenderProps) => ReactNode-Select content, or a function of the render props
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, SelectRenderProps>-Replaces the rendered element with a custom render function
...restEvery React Aria Select attribute is accepted, including aria-label

Select.Trigger

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNode | (values: SelectRenderProps) => ReactNode-Trigger content, or a function of the render props
...restEvery React Aria Button attribute is accepted

Select.Value

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNode | (values: SelectValueRenderProps<T>) => ReactNode-Value content, or a function of the render props
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, SelectValueRenderProps<T>>-Replaces the rendered element with a custom render function
...restEvery <span> attribute is accepted

Select.Indicator

A child element is cloned with the classes, data-slot="select-indicator" and data-open; without a child the default chevron renders.

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNode-Custom indicator element
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'svg'
...restEvery <svg> attribute is accepted

Select.ClearButton

Renders a span, so it nests validly inside the trigger button; it is aria-hidden and hidden while the selection is empty.

PropTypeDefaultDescription
classNamestring-Additional classes
childrenReactNode-Custom content, replacing the default icon
onClick(e: MouseEvent) => void-Handler called when the control is clicked
onPointerDown(e: PointerEvent) => void-Handler called on pointer down
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

Select.Popover

PropTypeDefaultDescription
placement"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom"Placement of the popover relative to the trigger
classNamestring-Additional classes
childrenReactNode-Content children
...restEvery React Aria Popover attribute is accepted

Render Props

Select and Select.Trigger children functions receive SelectRenderProps; Select.Value children functions receive these values:

PropTypeDescription
defaultChildrenReactNodeThe default rendered value
isPlaceholderbooleanWhether the value is a placeholder
selectedItemsNode<T>[]The currently selected items
selectedTextstringThe text of the selected items
stateSelectState<T>The state of the select

On this page