Performance: Why modals focus user attention
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 |
data-bs-backdrop='static' to prevent closing the modal when clicking outside, which helps keep focus inside.data-bs-backdrop='static' ensures keyboard focus stays inside the modal while open by blocking outside clicks.data-bs-focus='true' attribute (default).data-bs-focus='false').data-bs-focus='false' attribute on the modal [OK]data-bs-focus='true').Pass the test and this pattern moves unknown