Skip to content

Dialog

experimental

The Dialog component is a flexible and extensible content container overlaid on either the primary window or another dialog. It is based on the HTML <dialog> element and can be used to create both modal and non-modal dialog boxes. Modal dialog boxes interrupt interaction with the rest of the page being inert, while non-modal dialog boxes allow interaction with the rest of the page. Inert content outside an active dialog box is usually visually obscured or dimmed, making it difficult to discern. By default, modal overlays contain their own tab sequence, preventing users from navigating outside the component. The component implements the W3C ARIA APG Dialog (Modal) Pattern as well as the W3C ARIA APG Alert and Message Dialogs Pattern.

Examples

Base

A dialog is seperated into header, body and footer sections, which can be defined separately either through properties or template slots.
Be sure to provide a mechanism that allows users to close the dialog. The most reliable way to enable all users to close the dialogue box is to include an explicit button for this purpose, such as a 'Confirm', 'Cancel' or 'Close' button. The component specifies different types of user action that can be used to close the dialogue box. The main closeable property will add a close button to the dialog header. The closeOnBackdrop property adds a a light dismiss user action, which closes the dialog box when the user clicks or taps outside of it. The closeOnEscape property allows platform-specific user actions, such as pressing the ESC key on desktop platforms, or performing a "back" or "dismiss" gesture on mobile platforms, to close the dialog box. Furthermore, by setting the cancelButton or confirmButton properties, associated buttons will be rendered in the footer section. With closeOnConfirm, the confirm button can also be used to close the dialog.

A simple modal dialog box is created by setting the backdrop property, which inert the background. By default, attempting to interact with the backdrop closes the dialog box. Setting the blockScroll property removes the body scrollbar. However, the body retains a non-scrollable scrollbar to prevent the background from shifting. This will set the body to position="fixed", which may cause some layouts to break.

Alert

An alert dialog box is a modal dialog that interrupts the user's workflow to communicate an important message and acquire a response. It is defined by setting the alert property. Examples include action confirmation prompts and error message confirmations. The dialog will have the alertdialog WAI-ARIA role, enabling assistive technologies and browsers to distinguish it from other dialogs and giving them the option to treat it specially, e.g. by playing a system alert sound.

Form

One useful purpose of a dialog is to display forms within it. Each slot provides the close() and confirm()functions, which can be called from inside the slot content to trigger component events. Using the autofocus attribute to explicitly indicate the initial focus placement will help ensure the focus is initially set on the focusable element deemed to be the best initial focus placement for any particular dialog.

Fullscreen

Another variant of the component is the option to display a dialog that covers the full user viewport, which is available via the fullscreen property.

Image

The component provides a separate image section in the body where an image can be placed using the imageSrc property. For accessibility reasons, don't forget to add an imageAlt property too.

Position

You can quickly change the alignment of all the text in the dialog box using the textPosition property. Additionally, you can align the footer buttons independently using the buttonPosition property.

Slots

The component provides header, title, subtitle, content, footer as well as confirmButton and cancelButton named slots templates to customise HTML content.

Dynamic Component

Rather than using the default slot, the component prop allows to pass any component that will be programmatically rendered inside the dialog component. Furthermore, an inline component created with a render function can also be passed. Props and events can be passed to the component with props and events properties too.

Teleport

The teleport prop allows the dialog to be "teleported" into any DOM node outside the DOM hierarchy of the component placed in. By default, if only a boolean is passed, the diaog will be teleported to the document body. In addition, any other destination could be passed as string or the DOM Node element.

Programmatically

This component provides a programmatic interface that can be accessed by the useOruga() composable. The composable can be used from outside of the Vue instance. For example, it can be used in Pinia or Vue Router with this syntax:

    import { useOruga } from "@oruga-ui/oruga-next";
    const oruga = useOruga();
    oruga.dialog.open({...});
        

A programmatic instance returns a promise to await for. The promise gets resolved when the dialog gets closed.

Dialog Component

Dialog is a container to display content in an overlay window.

html
<o-dialog></o-dialog>

Props

Prop nameDescriptionTypeValuesDefault
activeWhether dialog is active or not, use v-model:active to make it two-way bindingboolean-false
alertThis enables the alertdialog role, allowing assistive technologies and browsers to distinguish alert dialogs from other dialogs.
Alert dialogs interrupt the user's workflow to communicate an important messages and acquire an explicit response.
Examples include error messages that require confirmation and other action confirmation prompts.
boolean-
animationCustom animation (transition name)string-
From config:
dialog: {
  animation: "zoom-out"
}
ariaCloseLabelAccessibility label for the close buttonstring-
From config:
dialog: {
  ariaCloseLabel: "Close"
}
ariaDescribedbyAccessibility aria-describedby to be passed to the div root element - if a title is set, it is linked to the titlestring-
ariaLabelAccessibility aria-label to be passed to the div root elementstring-
backdropShow an backdrop overlay background; make it a modal dialogboolean-
From config:
dialog: {
  backdrop: true
}
blockScrollWhether background scrollbar should be blocked/removed when dialog is visibleboolean-
From config:
dialog: {
  blockScroll: true
}
buttonPositionPosition of the footer buttons"center" | "left" | "right"-
cancelButtonRender a cancel button and set text text as labelstring-
cancelVariantColor variant of the cancel buttonstringprimary, info, success, warning, danger, and any other custom color
closeIconClose icon namestring-
From config:
dialog: {
  closeIcon: "close"
}
closeIconSizeClose icon sizestring-
From config:
dialog: {
  closeIconSize: undefined
}
closeOnBackdropClose the dialog when clicked outside of the panelboolean-
From config:
dialog: {
  closeOnBackdrop: true
}
closeOnConfirmClose the dialog when the confirm button is presetboolean-
From config:
dialog: {
  closeOnConfirm: false
}
closeOnEscapeClose the dialog when pressing escape keyboolean-
From config:
dialog: {
  closeOnEscape: true
}
closeableAdds close button to the header to hide the dialogboolean-
From config:
dialog: {
  closeable: false
}
componentComponent to be injected.
Close the component by emitting a 'close' event — $emit('close')
Component-
confirmButtonRender a confirm button and set text as labelstring-
confirmVariantColor variant of the confirm buttonstringprimary, info, success, warning, danger, and any other custom color
contentDialog body content, unnecessary when content slot is usedstring-
disableCancelDisable the cancel buttonboolean-
disableConfirmDisable the confirm buttonboolean-
eventsEvents to be binded to the injected component{}-
fullscreenDisplay dialog as full screenboolean-false
iconPackIcon pack to use for the close iconstringmdi, fa, fas and any other custom icon pack
From config:
dialog: {
  iconPack: undefined
}
imageAltDialog image alt, unnecessary when image slot is usedstring-
imageSrcDialog image src, unnecessary when image slot is usedstring-
loadingShow a loading spinner in the dialogboolean-
loadingLabelShow label beside the loading iconstring-
maxHeightMax height of the dialogNumberish-
From config:
dialog: {
  maxHeight: "80vh"
}
maxWidthMax width of the dialogNumberish-
From config:
dialog: {
  maxWidth: "80vw"
}
mobileBreakpointMobile breakpoint as max-width valuestring-
From config:
dialog: {
  mobileBreakpoint: undefined
}
overrideOverride existing theme classes completelyboolean-
propsProps to be binded to the injected componentany-
subtitleDialog header subtitle, unnecessary when subtitle slot is usedstring-
teleportAppend the component to another part of the DOM.
Set true to append the component to the body.
In addition, any CSS selector string or an actual DOM node can be used.
boolean | object | string-
From config:
dialog: {
  teleport: false
}
textPositionText alignment in its entirely"center" | "left" | "right"-
titleDialog header title, unnecessary when title slot is usedstring-

Events

Event namePropertiesDescription
update:activevalue boolean - updated active propactive prop two-way binding
closeevent Event - native eventthe event is fired when the dialog has been closed
cancelevent Event - native eventthe event is fired when the user wish to dismiss the current open dialog
confirmevent Event - native eventthe event is fired when the confirm button get clicked

Slots

NameDescriptionBindings
headerOverride the headerclose (event: Event): void - function to emit a close event
titleOverride the header title, default is title prop
subtitleOverride the header subtitle, default is subtitle prop
closeDefine a custom close icon
imageOverride the image
defaultOverride the default dialog bodyclose (event: Event): void - function to emit a close event
confirm (event: Event): void - function to emit a confirm event
contentOverride the body content, default is content propclose (event: Event): void - function to emit a close event
confirm (event: Event): void - function to emit a confirm event
footerOverride the footerclose (event: Event): void - function to emit a close event
confirm (event: Event): void - function to emit a confirm event
cancelButtonDefine the cancel button label
confirmButtonDefine the confirm button label

Class Inspector

Classes applied to the element:
Want to know how does the Class Inspector work?
Class propDescriptionPropsSuffixes
rootClass
Class of the root element.
mobileClass
Class of the root element when on mobile.
👉 Switch to mobile view to see it in action!
activeClass
Class of the root element when active.
active
fullscreenClass
Class of the root element when fullscreen.
fullscreen
teleportClass
Class of the root element when teleported.
teleport
textPositionClass
Class of the root element with text position.
textPositionleft
center
right
backdropClass
Class of the backdrop overlay element.
backdrop
wrapperClass
Class of the wrapper element.
headerClass
Class of the header element.
titleClass
Class of the header title element.
subtitleClass
Class of the header subtitle element.
closeClass
Class of the header close element.
figureClass
Class of the image figure element.
imageClass
Class of the image element.
bodyClass
Class of the body element.
contentClass
Class of the body content element.
footerClass
Class of the footer element.
footerPositionClass
Class of the footer element with position.
buttonPositionleft
center
right
confirmButtunClass
Class of the footer confirm button element.
confirmButton
cancelButtonClass
Class of the footer cancel button element.
cancelButton
scrollClipClass
Class of the body when dialog is active and has blockScroll.
blockScroll
scrollKeepClass
Class of the body when dialog is active and has not blockScroll.
blockScroll

Sass Variables

Current theme ➜ Oruga

The theme does not have any custom variables for this component.

Current theme ➜ Bulma

The theme does not have any custom variables for this component.

Current theme ➜ Bootstrap

The theme does not have any custom variables for this component.

Released under the MIT License.