Jump to main content

Modal


The modal component can be used to overlay an area of the screen which can contain a prompt, dialog or interaction.

On p-modal set display to display:flex or display:none to toggle the visibility of the modal.

The element that launches a given modal should include a trailing ellipsis, e.g. "Launch modal…". This is a convention used to indicate that the element launches a dialog.

Optional footer element with a p-modal__footer class name can be added to the modal dialog to provide additional options.

Accessibility

JavaScript should be used with the modal pattern to trap focus within an open modal, preventing elements behind the modal from unintentionally receiving focus via keyboard input. The examples on this page include JavaScript that can help to achieve this.

See WCAG Success Criterion 2.1.2 for further information.

Import

To import just this component into your project, copy the snippet below and include it in your main Sass file.

// import Vanilla and include base mixins
// this only needs to happen once in a given project
@import 'vanilla-framework/scss/vanilla';
@include vf-base;

@include vf-p-modal;

For more information see Customising Vanilla in your projects, which includes overrides and importing instructions.

React

You can use modal dialogs in React by installing our react-component library and importing Modal component.

See the documentation for our React Modal component