Skip to content
LIBRARYFeedback

Dialog ​

MDialog · A moment to decide.

Next alpha

Available in 0.1.0-alpha.4.

Web preview
Open example ↗

Usage ​

vue
<script setup lang="ts">
import { ref } from 'vue'
const open = ref(false)
const loading = ref(false)
const error = ref('')
async function confirm() {
  loading.value = true
  error.value = ''
  try {
    await saveChanges() // Your application's operation.
    open.value = false
  } catch {
    error.value = 'Could not save. Please try again.'
  } finally {
    loading.value = false
  }
}
</script>
<template>
  <m-screen>
    <m-button @click="open = true">Save changes</m-button>
    <m-dialog
      v-model:open="open"
      title="Save changes?"
      :description="error || 'Your profile will be updated.'"
      :loading="loading"
      confirmLabel="Save"
      cancelLabel="Keep editing"
      loadingLabel="Saving…"
      @confirm="confirm"
    />
  </m-screen>
</template>

saveChanges represents your application operation. confirm does not close the Dialog: the parent controls open, can show an error in description and permit another attempt. On NativeScript, place it inside MScreen and use the router back integration described in Sheet.

Props ​

PropTypeDefaultBehavior
openbooleanfalsev-model:open.
titlestringrequiredNonempty title and accessible name.
descriptionstring''Optional plain text. HTML is not interpreted.
tonedefault | dangerdefaultIcon and confirmation emphasis.
confirmLabelstringContinuePrimary action; nonempty.
cancelLabelstringCancelExplicit cancellation; nonempty.
loadingbooleanfalseBlocks actions, backdrop, Escape and back.
loadingLabelstringWorking…Confirmation label while processing; nonempty.
dismissiblebooleantrueAllows backdrop, Escape and back. Cancel remains available.
interactivebooleanfalseLets a downward drag on the title ask to dismiss, with reason swipe. Web hands the dialog to Jolt's interactive modal; NativeScript drags the in-page panel.
idstring—Modal surface identifier.

Events and lifecycle ​

  • confirm() requests the action and keeps the dialog open.
  • update:open(false) requests dismissal; the parent can accept or reject it.
  • close(reason) identifies cancel, backdrop, escape, back, program, navigation or, with interactive, swipe. It fires when dismissal is requested/started, before the animation finishes. A rejected request still reports its reason without leaving the dialog inert.

DialogCloseReason is exported by core. Setting open to false closes even while loading and emits program. Native navigation unload releases the layer and requests navigation, including retained pages; background unload preserves state for resume. On Web, route unmount removes the dialog and releases focus/scroll locking; it does not emit a navigation event.

The backdrop blocks the screen. On Web, Cancel receives initial focus; Tab stays between actions and closing restores a still-mounted opener. While processing, focus stays on the panel. Android handles back and Tab/Escape keys; iOS isolates modal content for assistive technology. This is not a comprehensive screen-reader or physical-device audit.

Long text scrolls inside the panel with actions in a separate area. Native opening dismisses the keyboard; the surface respects insets and follows rotation. Toast waits while the modal is presented.

Motion ​

On Web the dialog grows out of the button that opened it with the theme's spring and shrinks back toward it on close, even in Safari, which does not focus a clicked button. When nothing was pressed or focused, for example an opening from a timer, it lifts and fades in as before. NativeScript does not know the opener, so its panel lifts and settles with the same spring while the backdrop fades. A theme without press scale only fades. Reduced motion keeps the fade and drops the travel.

With interactive, dragging the title down far enough, or flicking it, asks to dismiss. A rejected or locked request springs the panel back; loading and dismissible=false disable the gesture. Cancel and Escape stay the accessible ways out.

Use one modal at a time. Do not open Dialog inside Sheet or Select. Arbitrary slots, forms, stacking, global services and promise helpers are outside this first contract. Use Sheet for custom content.

Interaction recordings ​

iPhone Simulator. A short title drag returns the panel to its starting position. The second drag dismisses the publish dialog.

Android emulator. A short title drag returns the panel to its starting position. The second drag dismisses the publish dialog.

Chromium. A short title drag returns the panel to its starting position. The second drag dismisses the publish dialog.

Desktop ​

MDialog opens inside the window on the Mac and on Windows, keeps the keyboard until it closes and gives it back to the control that opened it; Enter runs the focused button or confirms, and Escape or the scrim cancel. interactive has no effect, since dragging the title is a touch gesture. See Desktop components.

Full example ​

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, onBeforeUnmount, ref } from 'vue'
import { useMavisTheme, useToast } from '@getcortexlabs/mavis-core/vue'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const { theme } = useMavisTheme()
const toast = useToast()
const open = ref(false)
const danger = ref(false)
const loading = ref(false)
let timer: ReturnType<typeof setTimeout> | undefined
function show(destructive: boolean) {
  danger.value = destructive
  open.value = true
}
function confirm() {
  loading.value = true
  timer = setTimeout(() => {
    loading.value = false
    open.value = false
    toast.show({
      title: pt.value ? 'Tudo certo.' : 'All done.',
      message: pt.value ? 'Ação concluída nesta demonstração.' : 'Action completed in this demo.',
      tone: 'success',
    })
  }, 1200)
}
onBeforeUnmount(() => clearTimeout(timer))
</script>

<template>
  <m-column gap="lg">
    <m-column padding="lg" gap="lg" radius="lg" :backgroundColor="theme.colors.primarySoft">
      <m-row justify="between" gap="sm">
        <m-text variant="overline" tone="primary">{{
          t(pt ? 'ANTES DO PRÓXIMO PASSO' : 'BEFORE THE NEXT STEP')
        }}</m-text>
        <m-icon name="sparkles" tone="primary" />
      </m-row>
      <m-text variant="title">{{ t(pt ? 'Vale uma pausa.' : 'A moment to decide.') }}</m-text>
      <m-text tone="muted">{{
        t(
          pt
            ? 'Algumas decisões merecem a sua atenção. Duas escolhas claras, no centro da tela.'
            : 'Some decisions deserve your attention. Two clear choices, at the center of the screen.',
        )
      }}</m-text>
      <m-column padding="md" gap="md" radius="md" :backgroundColor="theme.colors.surface">
        <m-row gap="sm"
          ><m-icon name="circle-check" tone="primary" /><m-text :style="{ fontWeight: '600' }">{{
            t(pt ? 'Pronto para publicar?' : 'Ready to publish?')
          }}</m-text></m-row
        >
        <m-text variant="caption" tone="muted">{{
          t(
            pt
              ? 'Sua coleção, pronta para ganhar o mundo.'
              : 'Your collection, ready to meet the world.',
          )
        }}</m-text>
        <m-button @click="show(false)">{{
          t(pt ? 'Publicar coleção' : 'Publish collection')
        }}</m-button>
      </m-column>
    </m-column>
    <m-card gap="md">
      <m-row gap="sm"
        ><m-icon name="triangle-alert" tone="danger" /><m-text variant="heading">{{
          t(pt ? 'Com cuidado.' : 'With care.')
        }}</m-text></m-row
      >
      <m-text tone="muted">{{
        t(
          pt
            ? 'Quando não dá para voltar atrás, a consequência precisa ficar clara.'
            : 'When a choice cannot be undone, make the consequence clear.',
        )
      }}</m-text>
      <m-button variant="secondary" @click="show(true)">{{
        t(pt ? 'Excluir coleção' : 'Delete collection')
      }}</m-button>
    </m-card>
    <m-text variant="caption" tone="muted">{{
      t(
        pt
          ? 'Demonstração local. Nenhuma coleção será publicada ou excluída. Para fechar a primeira, arraste o título para baixo.'
          : 'Local demo. No collection will be published or deleted. Drag the first one down by its title to close it.',
      )
    }}</m-text>
    <m-dialog
      v-model:open="open"
      :interactive="!danger"
      :loading="loading"
      :tone="danger ? 'danger' : 'default'"
      :title="
        t(
          danger
            ? pt
              ? 'Excluir esta coleção?'
              : 'Delete this collection?'
            : pt
              ? 'Compartilhar sua coleção?'
              : 'Share your collection?',
        )
      "
      :description="
        t(
          danger
            ? pt
              ? 'As fotos e anotações desta coleção serão removidas. Esta ação não pode ser desfeita.'
              : 'The photos and notes in this collection will be removed. This cannot be undone.'
            : pt
              ? 'As pessoas que acompanham você poderão ver as fotos e deixar comentários.'
              : 'People who follow you will be able to see the photos and leave comments.',
        )
      "
      :confirmLabel="danger ? (pt ? 'Excluir' : 'Delete') : pt ? 'Publicar' : 'Publish'"
      :cancelLabel="pt ? 'Agora não' : 'Not now'"
      :loadingLabel="t(pt ? 'Aguarde…' : 'Please wait…')"
      @confirm="confirm"
    />
    <m-toast :controller="toast" :closeLabel="t(pt ? 'Fechar aviso' : 'Dismiss notice')" />
  </m-column>
</template>

Profile requests confirmation before discarding edits.

Experimental image, icon, Sheet and Dialog integrations are described in Images and physics. They require Jolt RC.11 and are included in Mavis alpha.8.

Components for NativeScript and Web. Starting with Vue.