What happens when the modal is open and the user presses the Tab key repeatedly?
medium
A. Focus moves to elements outside the modal as well
B. Focus moves to the browser address bar
C. Focus gets stuck on the first button inside the modal
D. Focus cycles only between elements inside the modal
Solution
Step 1: Understand Bootstrap modal focus trap
Bootstrap traps keyboard focus inside the modal when open, cycling through modal elements only.
Step 2: Analyze Tab key behavior
Pressing Tab moves focus forward inside modal elements, looping back to first element after last.
Final Answer:
Focus cycles only between elements inside the modal -> Option D
Quick Check:
Tab key cycles focus inside modal [OK]
Hint: Tab cycles focus inside modal elements only [OK]
Common Mistakes:
Thinking focus escapes modal on Tab
Assuming focus gets stuck on one element
Believing focus moves outside modal to browser
4. You notice that after opening a Bootstrap modal, keyboard focus is not trapped inside it and users can tab to background page elements. What is the likely cause?
medium
A. The modal is missing the tabindex='-1' attribute
B. The modal has aria-modal='false' set
C. The modal content is missing a close button
D. The modal is missing the data-bs-backdrop attribute
Solution
Step 1: Check tabindex attribute role in focus trapping
Bootstrap requires tabindex='-1' on the modal container to manage focus properly.
Step 2: Identify cause of focus escape
Without tabindex='-1', focus trapping fails and keyboard can move outside modal.
Final Answer:
The modal is missing the tabindex='-1' attribute -> Option A
Quick Check:
Missing tabindex='-1' breaks focus trap [OK]
Hint: Ensure tabindex='-1' on modal container for focus trap [OK]
Common Mistakes:
Thinking aria-modal='false' causes focus issues
Assuming close button affects focus trap
Confusing backdrop attribute with focus behavior
5. You want to customize a Bootstrap modal so that when it closes, focus returns to the button that opened it. Which approach correctly manages focus for accessibility?
hard
A. Use tabindex='0' on the modal container to trap focus
B. Set autofocus attribute on the modal's close button
C. Add a JavaScript event listener on modal close to focus the opener button
D. Disable Bootstrap's focus trap and manage focus manually