vUX / ModalDisplayer / v4.1.0

Dialogs that stack.

Mark up a trigger, hide your content, and a single delegated listener does the rest. A trigger inside an open dialog opens another on top of it.

<button class="open-modal" data-form="loginModal">Sign in</button>

01Effects & overlay

Every setting below is a property on .config. Effect changes apply immediately; the overlay settings are snapshotted when a modal opens, so they take effect from the next open.

config

Off means a click on the overlay no longer closes it.

equivalent code

                
applies from next open

02Stacking

Sign in → Forgot password → Terms is three layers deep. Each layer gets its own overlay, its own width and its own scroll container. Esc, an overlay click and a close button all pop only the topmost layer.

0
open layers
reads modal.depth
sign in reset terms

A page-level button cannot dismiss a stack: the overlay blocks the page, which is the whole point of a modal. So closeAll() lives inside the deeper dialogs, where it is actually reachable.

openProcessor / closeProcessor

03Per-trigger widths, and one shared stack

config.modalWidthsAttribute lets a single trigger override the responsive widths for the modal it opens, without leaking into the next one. And the stack is shared by all instances, because the state it protects (the body freeze) belongs to the document.

↔

Width per trigger

Same modal, three triggers, three widths. A trigger without the attribute falls back to the defaults.

⧉

A second instance

“Help”, inside Profile settings, is opened by a different ModalDisplayer with its own trigger class and effect, yet it layers correctly and one Esc still pops exactly one layer.

↕

Taller than the viewport

A tall modal scrolls inside its own overlay while the page behind stays exactly where it was.

04Bad input fails immediately

Every .config setter validates, and initialize() refuses an incomplete setup. Each button below performs the call and prints what was thrown.

No error yet: press one of the buttons above.

05The page keeps its place

Scroll down, then open a modal. The page is held with overflow:hidden rather than by taking the body out of flow, so it keeps both its scroll position and its layout.

Scroll to here, then press Esc-able open below: the page will not jump.
layer · sign in

Sign in


Triggers in here stack a new layer on top of this one.

layer 2 · reset

Reset password

Opened from inside the sign-in modal: the one underneath stays open and intact.

layer 3 · terms

Terms

Three layers deep. Esc pops one at a time, in reverse order.

layer · profile

Profile settings

An independent modal, opened straight from the page.

layer 2 · confirm

Are you sure?

This confirm sits above the profile modal that opened it.

other instance

Help

Opened by a different ModalDisplayer with its own effect, yet it stacks correctly and one Esc still pops exactly one layer.

scrolling

Taller than the viewport

This scrolls inside its own overlay. The page behind stays exactly where it was.