A modal manager is a stack of interaction owners, not a collection of high
z-indexvalues. Only the top dialog accepts input. The rest of the page is inert, focus stays within the top dialog, Escape follows product policy, and every close operation restores focus and global effects exactly once.
A centered panel and dark backdrop can still be an inaccessible overlay. The platform has to coordinate focus, keyboard dismissal, pointer dismissal, scroll locking, nested layers, routes, animations, and cleanup.
The design becomes manageable when one stack owns those cross-cutting effects.
Start with interaction ownership
Each open modal contributes one stack record:
- stable dialog ID;
- opener or explicit focus-return target;
- initial focus policy;
- Escape and backdrop dismissal policy;
- scroll-lock and inertness contribution;
- lifecycle phase and cleanup handles.
Only the top record is active. A nested confirmation sits above its parent editor. Closing the confirmation restores focus to the parent, not to the page behind both dialogs.
The public interview prompt
Design a reusable modal and nested-dialog manager for a frontend platform. Explain:
- dialog identity, stack ownership, lifecycle phases, and controlled APIs;
- portal placement, the browser top layer, stacking contexts, inertness, and scroll locking;
- initial focus, tab containment, Escape, backdrop dismissal, and focus restoration;
- nested dialogs, async actions, route changes, errors, animation, and cleanup;
- keyboard, screen-reader, pointer, touch, zoom, and mobile behavior;
- security, observability, testing, rollout, and evolution.
Assume product teams can supply arbitrary dialog content. Version one supports modal dialogs and nested confirmations, not movable windows, non-modal palettes, or cross-tab coordination.
What the premium solution covers
The complete solution defines stack records, a reducer, native-dialog and portal adapters, top-layer behavior, inertness, focus and dismissal contracts, nested restoration, scroll-lock reference counting, transition phases, async and navigation failures, mobile sheets, accessibility details, security boundaries, telemetry, deterministic tests, rollout gates, and an interview scoring rubric.
Original media shows how top-layer ownership moves through a nested stack and how restoration targets form a ledger. A deterministic lab lets you open and close nested layers while inspecting which surface owns focus and where it returns.