Skip to content

<XrDialog> ​

A modal panel for a question that needs an answer now: confirm a delete, name a file, accept a permission. It opens in front of the viewer wherever they look, at reading distance and facing them, over a backdrop that dims and blocks the UI behind it.

Usage ​

vue
<script setup lang="ts">
const open = ref(false)
</script>

<template>
  <XrButton @click="open = true">Delete…</XrButton>

  <XrDialog v-model:open="open" title="Delete playlist?">
    <XrText muted>This cannot be undone.</XrText>
    <template #actions>
      <XrButton variant="secondary" @click="open = false">Cancel</XrButton>
      <XrButton @click="remove">Delete</XrButton>
    </template>
  </XrDialog>
</template>

Put <XrDialog> at the top level of the scene, not inside another panel: it places itself.

Closing ​

The dialog closes itself, setting open to false and emitting close with the reason, on:

  • the × button in the header (button), hidden with :closable="false";
  • Escape on a desktop keyboard (escape), off with :close-on-escape="false";
  • a press on the backdrop (backdrop), with any input: mouse, controller ray, pinch or fingertip. Off with :close-on-backdrop="false".

Your own buttons close it by setting open to false; that emits no close.

Placement and the backdrop ​

When open turns true, the dialog is placed in front of the viewer's head, level with their eyes and turned to face them. In a session that is the headset; on a desktop it is the camera. Pass position to open it at a fixed place instead.

It opens a little closer than other UI (0.75 × the theme's viewingDistance, scaled so it looks the same size), so it reads as on top of it.

The backdrop dims the whole scene: it is a sphere around the viewer's head, seen from inside and drawn over everything except the dialog, so it covers what is behind you and what is close to you too, and there is nothing to walk through. It fades in, follows the head, and takes every controller ray or pinch that misses the dialog (a press on it closes the dialog). Fingertips do not press it: a poke beside the dialog does nothing. Popups and tooltips inside the dialog draw over it. :backdrop="false" turns it off; the dialog is then not modal.

The backdrop colour and its opacity are the theme's colors.scrim.

Focus and stacked dialogs ​

While a dialog is open, text fields outside it cannot take focus: a field that had it loses it, Tab or a focus() call on a field behind gives it straight back, and an XrKeyboard stops typing into it. Fields inside the dialog work as usual. On close, the keyboard types into the field it typed into before, and that field gets focus back if it had it when the dialog opened.

A dialog opened while another is open (a "really?" after a "delete?") opens a little closer to the viewer, in front of the first and over its backdrop. Escape closes only the topmost one.

API ​

Props ​

PropTypeDefaultDescription
widthnumber480Width of the dialog in dmm.
uiRecord<string, unknown>{}Escape hatch: raw uikit (@pmndrs/uikit) properties for the panel, merged last.
partsPartial<Record<"header" | "title" | "close" | "actions", Record<string, unknown>>>Raw uikit properties per inner part, merged after the defaults: header (title row), title, close (the × button), actions (the actions row).
backdropbooleantrueDim and block what is behind the dialog.
openbooleanWhether the dialog is shown. Use with v-model:open.
closablebooleantrueShow the Close button in the header.
closeOnBackdropbooleantrueClose on a press on the backdrop.
closeOnEscapebooleantrueClose on Escape (desktop keyboard).
positionVec3Where to open, in scene coordinates, instead of in front of the viewer. It then faces the viewer from there.
titlestringTitle in the header. The title slot replaces it.
distancenumberDistance from the viewer in metres when it opens. Defaults to 0.75 × the theme's viewingDistance, in front of other panels. Also sets the scale, so the dialog looks the same size at any distance; with position, pass the distance it ends up at.

Events ​

EventPayloadDescription
closereason: "button" | "escape" | "backdrop"The dialog was closed by its Close button, Escape or the backdrop. reason says which.
update:openopen: booleanThe dialog asks to open or close (v-model:open).

MIT License