Skip to content

<XrSelect> ​

A dropdown: a field that shows the chosen option and, when pressed, opens a list of options floating over the content around it. It opens and chooses with every input: mouse, controller ray, pinch and fingertip.

Usage ​

vue
<script setup lang="ts">
const quality = ref('High')
const voice = ref<string>()
</script>

<template>
  <XrSelect v-model="quality" :options="['Low', 'Medium', 'High']" />

  <XrSelect
    v-model="voice"
    placeholder="Pick a voice"
    :options="[
      { label: 'Nova', value: 'nova', description: 'Warm and calm' },
      { label: 'Echo', value: 'echo' },
      { label: 'Ember', value: 'ember', description: 'Coming soon', disabled: true },
    ]"
  />
</template>

Options are strings (the label is the value) or XrSelectOption objects: { label, value, description?, disabled? }, where value is a string or a number. Until modelValue matches an option, the field shows placeholder, muted.

Choosing an option emits update:modelValue, and change when the value is a new one.

Opening and closing ​

A press on the field opens the list, below it, or above it with placement="top". The list is drawn over whatever is around it, a little closer to the viewer, and takes the pointer first where it overlaps other UI: a press on an option never reaches the control behind it. It scrolls when it is taller than maxHeight (dmm).

It closes, emitting close, on:

  • a choice;
  • another press on the field;
  • Escape on a desktop keyboard;
  • a press anywhere outside it: on other vue-xr-ui UI or on empty space, with any input. Unlike a dialog's backdrop, a press outside that lands on another control also presses that control.

Presses on your own three.js objects (a mesh with @click) are not seen and leave it open. A hand's pinch is a press of its ray, wherever the ray points; a fingertip closes it when it pokes other UI.

The list is a layout root of its own that follows the field every frame (it is named <name>-popup after the select), so a container that clips the select (an XrList, anything with overflow: hidden or scroll) does not clip the list: a select in a row of a scrolling settings list opens fully. Options are named option-<value>.

open() and close() are exposed on the component's ref.

API ​

Props ​

PropTypeDefaultDescription
uiRecord<string, unknown>{}Escape hatch: raw uikit (@pmndrs/uikit) properties for the outer container, merged last.
maxHeightnumber240Height (dmm) above which the list scrolls.
disabledbooleanGreys the field out and closes the list; it then does not open.
partsPartial<Record<"option" | "value" | "trigger" | "chevron" | "popup", Record<string, unknown>>>Raw uikit properties per inner part, merged after the defaults: trigger (the field), value (its text), chevron, popup (the floating list's panel), option (every row).
optionsreadonly (string | XrSelectOption)[][]The choices: strings, or { label, value, description?, disabled? }.
placeholderstring'Select…'Shown, muted, while no option is chosen.
placement"top" | "bottom"'bottom'Open the list below the field (bottom) or above it (top).
modelValueXrSelectValueThe chosen option's value. Use with v-model.

Events ​

EventPayloadDescription
changevalue: XrSelectValue, option: XrSelectOptionAn option other than the current one was chosen.
closeThe list closed, by a choice or otherwise.
update:modelValuevalue: XrSelectValueAn option was chosen (v-model).
openThe list opened.

MIT License