Select

Select

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

Usage

Import all parts and piece them together. It's mandatory to wrap the whole component with the Tailwind tag.

const { Tailwind } = VM.require("uiisnear.near/widget/tailwind");
const {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectTrigger,
  SelectValue,
} = VM.require("uiisnear.near/widget/select");
 
if (Tailwind == undefined) return "";
<Tailwind>
  <Select>
    <SelectTrigger className="w-96">
      <SelectValue placeholder="Theme" />
    </SelectTrigger>
    <SelectContent>
      <SelectItem value="light">Light</SelectItem>
      <SelectItem value="dark">Dark</SelectItem>
      <SelectItem value="system">System</SelectItem>
    </SelectContent>
  </Select>
</Tailwind>

API Reference

Select

Contains all the parts of a select.

PropTypeDefault
defaultValue
string
---
value
string
---
onValueChange
function
---
defaultOpen
boolean
---
open
boolean
---
onOpenChange
function
---
dir
enum
---
name
string
---
disabled
boolean
---
required
boolean
---

SelectTrigger

The button that toggles the select. The SelectContent will position itself by aligning over the trigger.

Data attributeValues
[data-state]"open" | "closed"
[data-disabled]Present when disabled
[data-placeholder]Present when has placeholder

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.

PropTypeDefault
placeholder
ReactNode
---

SelectContent

The component that pops out when the select is open.

PropTypeDefault
onCloseAutoFocus
function
---
onEscapeKeyDown
function
---
onPointerDownOutside
function
---
position
enum
"item-aligned"
side
enum
"bottom"
sideOffset
number
0
align
enum
"start"
alignOffset
number
0
avoidCollisions
boolean
true
collisionBoundary
Boundary
[]
collisionPadding
number | Padding
0
arrowPadding
number
0
sticky
enum
"partial"
hideWhenDetached
boolean
false
Data attributeValues
[data-state]"open" | "closed"
[data-side]"left" | "right" | "bottom" | "top"
[data-align]"start" | "end" | "center"

SelectItem

The component that contains the select items.

PropTypeDefault
value*
string
---
disabled
boolean
---
textValue
string
---
Data attributeValues
[data-state]"checked" | "unchecked"
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

SelectLabel

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

SelectSeparator

Used to visually separate items in the select.

SelectGroup

Used to group multiple items. use in conjunction with SelectLabel to ensure good accessibility via automatic labelling.

Classnames

Classnames available to customize the component.

FunctionClassname
SelectTriggerselectTriggerClassname
SelectScrollUpButtonselectScrollUpButtonClassname
SelectScrollDownButtonselectScrollDownButtonClassname
SelectLabelselectLabelClassname
SelectItemselectItemClassname
SelectSeparatorselectSeparatorClassname

Examples

Scrollable