Skip to content

MazBackdrop

MazBackdrop is a flexible backdrop component that provides a foundation for modals, drawers, bottom sheets and any overlay content. It handles focus management, keyboard navigation, and animations automatically.

TIP

This component uses <Teleport to="body"> and is the foundation for MazDialog, MazDrawer, and MazBottomSheet

Basic usage

MazBackdrop creates a semi-transparent overlay that covers the entire screen. Think of it like a dark blanket that appears behind your content to make it stand out.

Persistent backdrop

A persistent backdrop cannot be closed by clicking outside or pressing Escape. Perfect for important confirmations!

Content positioning

You can control where your content appears using justify and align props. It's like choosing where to place a sticker on your screen!

Custom animations

MazBackdrop comes with built-in animations, but you can customize them with the transition-name prop.

Accessibility features

MazBackdrop automatically handles:

  • Focus trap: Tab navigation stays within your content
  • Keyboard support: Escape key to close (unless persistent)
  • Screen readers: Proper ARIA attributes for accessibility
  • Scroll lock: Prevents background scrolling when open

These features work automatically - you don't need to do anything extra!

Props

NameDescriptionTypeRequired
model-valuev-model
booleanNo
teleport-selectorTeleport selectorstringNo
before-closeFunction called before modal is closeTSFunctionTypeNo
persistentPersistent dialog (not closable by clicking outside and remove close button)booleanNo
close-on-escapePrevent close on escape keybooleanNo
transition-nameTransition namestringNo
backdrop-classBackdrop classNative typeNo
backdrop-content-classBackdrop content classNative typeNo
content-paddingAdd padding to the contentbooleanNo
justifyJustify content"center" | "end" | "start" | "space-between" | "space-around" | "none"No
alignAlign content"center" | "end" | "start" | "none"No
variantVariant"bottom-sheet" | "dialog" | "drawer"No
aria-labelledbyID for aria-labelledbystringNo
aria-describedbyID for aria-describedbystringNo

Events

Event namePropertiesDescription
openEmitted when modal is open
closeEmitted when modal is close
update:model-valuevalue boolean - The value of the modelEmitted when modal is open or close
before-closeEmitted before modal is close

Slots

NameDescriptionBindings
defaultPlace your content hereclose Function - close function

Expose

onBackdropAnimationLeave

Animation leave event
@description This is used to handle animation leave events

close

Close the backdrop
@description This is used to close the backdrop

present

The present state of the backdrop
@description This is used to check if the backdrop is present (open)

toggleModal

Toggle the backdrop
@description This is used to toggle the backdrop
@param The value to toggle the backdrop (optional)

onKeyPress

Key press event
@description This is used to handle key press events