Skip to content

Modal

Displays dialog content on top of the main page, requiring user interaction.

First release: 1.0.0 Latest update: July 1, 2025 Current version: 1.0.0

React Angular Vue Svelte HTML

Import

import { PlusModal } from '@plusui/react';
import { PlusModalComponent } from '@plusui/angular';
import { PlusModal } from '@plusui/vue';
import PlusModal from '@plusui/svelte';
<script src="https://cdn.jsdelivr.net/npm/@plusui/core"></script>

Package

@plusui/react
@plusui/angular
@plusui/vue
@plusui/svelte
@plusui/core

Docs

Changelog

Modal Changelog

Recent changes and updates for the modal component

v1.0.0

June 20, 2025
Feat

Added Modal component for dialogs

  • Multiple sizes: sm, md, lg
  • Custom header, body, and footer slots
  • Backdrop click to close
  • Keyboard navigation (Escape to close)
  • Accessibility with ARIA attributes

The Modal component displays a dialog window on top of the main content. It’s used to focus the user’s attention on a specific task, information, or action without navigating away from the current page. Modals typically include a header, body, footer, and a close mechanism.

Modal - anatomy

To use the modal, you typically need a trigger element (like a button) to open it and controls within the modal to close it. The modal’s visibility is controlled programmatically using its show() and hide() methods.

Open Modal
Modal Title
This is the main content of the modal.
CloseSave Changes
Show code
Show console

The size prop controls the width of the modal dialog.

Small
Small Modal
Content for small modal…
Close
Large
Large Modal
Content for large modal…
Close
Full Width
Full Width Modal
Content for full width modal…
Close
Show code

Control how the modal closes using close-on-backdrop and close-on-esc.

No Backdrop Close
No Backdrop Close
You must use the close button or Esc key.
Close
No Esc Close
No Esc Close
You must use the close button or click the backdrop.
Close
Show code
Modal - layout spacing Modal - light & dark mode
  • Keyboard Behavior:
    • When the modal is open, focus should be trapped within the modal. Users should be able to navigate interactive elements inside the modal using Tab and Shift+Tab. (Note: Focus trapping needs to be implemented by the developer or a utility library, as it’s not built into the component’s provided code snippet).
    • The modal can be closed using the Escape key (if close-on-esc is true).
    • The close button (<slot name="close"> or default) should be focusable and activatable with Enter or Space.
  • Screen Reader:
    • The component uses role="dialog" and aria-modal="true" to indicate its purpose and that interaction with the underlying page is blocked.
    • aria-hidden is toggled based on the isOpen state to hide/show the modal from assistive technologies.
    • It’s recommended to set an accessible name for the modal using aria-labelledby pointing to the header slot’s content ID, or aria-label directly on the plus-modal element, especially if the header is complex or absent.
    • The default close button has an aria-label="Close modal". If providing a custom close button via the close slot, ensure it also has an appropriate accessible label.
  • Required Developer Actions:
    • Implement focus trapping when the modal is open to prevent users from tabbing outside the modal content.
    • Provide a clear and descriptive header (<slot name="header">) or use aria-label/aria-labelledby on the plus-modal element.
    • Ensure interactive elements within the modal body and footer are keyboard accessible.
    • If using a custom close button in the close slot, provide an appropriate aria-label.
NameTypeDefaultDescriptionRequired
size'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full''md'The size (width) of the modal.No
isOpenbooleanfalseControls whether the modal is currently visible.No
fullWidthbooleanfalseIf true, the modal ignores the size prop and takes full width.No
closeOnBackdropbooleantrueAllows closing the modal by clicking the background overlay.No
closeOnEscbooleantrueAllows closing the modal by pressing the Escape key.No
animationDurationnumber300Duration of the open/close animation in milliseconds.No
NamePayload TypeDescription
plus-modal-before-showCustomEvent<void>Fired just before the modal starts to open.
plus-modal-showCustomEvent<void>Fired after the modal has fully opened.
plus-modal-before-hideCustomEvent<void>Fired just before the modal starts to close.
plus-modal-hideCustomEvent<void>Fired after the modal has fully closed.
NameParametersReturnsDescription
show()—voidOpens the modal. Triggers plus-modal-before-show and plus-modal-show.
hide()—voidCloses the modal. Triggers plus-modal-before-hide and plus-modal-hide.
NameDescription
headerContent for the modal’s header area.
bodyThe main content area of the modal.
default (unnamed)Also used for the main content if body slot is not used.
footerContent for the modal’s footer area (typically for buttons).
closeCustom content for the close button (replaces the default X).
PartDescription
containerThe main container element (includes overlay and modal).
overlayThe background overlay element.
modalThe modal dialog window itself.
headerThe header section of the modal.
bodyThe main content body section.
footerThe footer section of the modal.
close-buttonThe close button element (default or slotted).

Join the Community

Plus UI is built by the community. Join us on our platforms to contribute, get help, and stay up to date.