Components
Select

Select

Displays a list of options for the user to pick from—triggered by a button.

Thành phố
Help message

Usage

import {
  Select,
  SelectGroup,
  SelectValue,
  SelectTrigger,
  SelectContent,
  SelectLabel,
  SelectItem,
  SelectSeparator,
  SelectScrollUpButton,
  SelectScrollDownButton,
} from "@momo-webplatform/mobase";
<Select label="Thành phố" message="Help message">
  <SelectTrigger className="w-[250px]">
    <SelectValue placeholder="Select a value" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel>Thành phố</SelectLabel>
      <SelectItem value="Hồ Chí Minh">Hồ Chí Minh</SelectItem>
      <SelectItem value="Nha Trang">Nha Trang</SelectItem>
      <SelectItem value="Đà Lạt">Đà Lạt</SelectItem>
      <SelectItem value="Vũng Tàu">Vũng Tàu</SelectItem>
      <SelectItem value="Huế">Huế</SelectItem>
    </SelectGroup>
    <SelectGroup>
      <SelectLabel>Tennis player</SelectLabel>
      <SelectItem value="Roger Federer" disabled>Roger Federer</SelectItem>
      <SelectItem value="Rafael Nadal">Rafael Nadal</SelectItem>
      <SelectItem value="Novak Djokovic">Novak Djokovic</SelectItem>
      <SelectItem value="Andy Murray" disabled>Andy Murray</SelectItem>
    </SelectGroup>
    <SelectGroup>
      <SelectLabel>Waifu</SelectLabel>
      <SelectItem value="Ganyu">Ganyu</SelectItem>
      <SelectItem value="Kamisato Ayaka">Kamisato Ayaka</SelectItem>
      <SelectItem value="Jean">Jean</SelectItem>
      <SelectItem value="Nilou">Nilou</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

Examples

Status

  • Focused: The select has been navigated to and is ready to accept input.
  • Error: The value failed validation.
  • Disabled: The select cannot accept select or become focused.

Empty

Thành phố
Help message
Thành phố
Help message

Filled

Thành phố
Help message
Thành phố
Help message

Error

Thành phố
Help message
Thành phố
Help message

Disabled

Thành phố
Help message
Thành phố
Help message

Size

Select has 2 different sizes:

Default

Thành phố
Help message

Large

Thành phố
Help message

API Reference

Select component extends Radix Select (opens in a new tab) component and supports all of its props.

Select
PropTypeDefaultRequired
value
string--false
defaultValue
string--false
onValueChange
(value: string) => void--false
open
enumboolean--false
defaultOpen
enumboolean--false
onOpenChange
(open: boolean) => void--false
dir
enumDirection--false
name
string--false
autoComplete
string--false
disabled
enumboolean--false
required
enumboolean--false
className
string--false
label
string--false
message
string--false
size
enum1 | 2--false
isError
enumboolean--false
SelectGroup
PropTypeDefaultRequired
asChild
enumboolean--false
SelectValue
PropTypeDefaultRequired
placeholder
enumReactNode--false
asChild
enumboolean--false
SelectTrigger
PropTypeDefaultRequired
asChild
enumboolean--false
SelectContent
PropTypeDefaultRequired
asChild
enumboolean--false
side
enumtop | right | bottom | left--false
sideOffset
number--false
align
enumcenter | start | end--false
alignOffset
number--false
arrowPadding
number--false
avoidCollisions
enumboolean--false
collisionBoundary
enumElement | Element[]--false
collisionPadding
enumnumber | Partial<Record<top | right | bottom | left, number>>--false
sticky
enumpartial | always--false
hideWhenDetached
enumboolean--false
updatePositionStrategy
enumalways | optimized--false
onCloseAutoFocus
(event: Event) => void--false
onEscapeKeyDown
(event: KeyboardEvent) => void--false
onPointerDownOutside
(event: PointerDownOutsideEvent) => void--false
position
enumitem-aligned | popper popper false
SelectLabel
PropTypeDefaultRequired
asChild
enumboolean--false
SelectItem
PropTypeDefaultRequired
value
string--true
disabled
enumboolean--false
asChild
enumboolean--false
textValue
string--false
SelectSeparator
PropTypeDefaultRequired
asChild
enumboolean--false
SelectScrollUpButton
PropTypeDefaultRequired
asChild
enumboolean--false
SelectScrollDownButton
PropTypeDefaultRequired
asChild
enumboolean--false

Best practices

  • Use a select input for longer lists of options. If there are 6 or fewer options and you don't need to conserve vertical space, consider using a Radio component (opens in a new tab) instead.

  • Provide a default selected option when possible

  • Order the menu options in a logical order to make it easier for users to find the option they're looking for. Default to alphabetical order.