Performance: Why modals focus user attention
MEDIUM IMPACT
Modals affect interaction responsiveness and visual stability by controlling focus and overlaying content.
const modal = document.getElementById('modal'); modal.style.display = 'block'; modal.querySelector('button, [tabindex]:not([tabindex="-1"])').focus(); // Trap focus inside modal
const modal = document.getElementById('modal'); modal.style.display = 'block'; // No focus management
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No focus management in modal | Minimal DOM changes | 0 reflows triggered by focus | Paint triggered by overlay | [X] Bad |
| Focus moved and trapped inside modal | Focus moved programmatically | 1 reflow for focus outline | Paint for overlay and focus styles | [OK] Good |