Challenge - 5 Problems
Keyboard Navigation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ accessibility
intermediateKeyboard focus order in Bootstrap modal
Consider a Bootstrap modal with multiple interactive elements. What is the default keyboard focus order when the modal opens?
Bootsrap
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Open Modal</button> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <input type="text" class="form-control" placeholder="Input 1"> <input type="text" class="form-control mt-2" placeholder="Input 2"> <button class="btn btn-secondary mt-3">Submit</button> </div> </div> </div> </div>
Attempts:
2 left
💡 Hint
Think about which element is designed for quick dismissal and accessibility in Bootstrap modals.
✗ Incorrect
Bootstrap modals automatically focus the first focusable element inside the modal when opened, which is typically the first input element. The focus then cycles through all focusable elements inside the modal in DOM order.
❓ selector
intermediateSelecting focusable elements for keyboard navigation
Which CSS selector correctly targets all focusable elements inside a Bootstrap navbar for custom keyboard navigation?
Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Brand</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link active" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Pricing</a> </li> </ul> </div> </nav>
Attempts:
2 left
💡 Hint
Remember that some elements may have tabindex attributes to be focusable.
✗ Incorrect
Option C covers all standard focusable elements inside the navbar and also includes elements with tabindex not equal to -1, ensuring comprehensive keyboard navigation support.
❓ rendering
advancedVisual focus indicator for keyboard users
You want to improve keyboard navigation by adding a visible focus outline to all buttons in a Bootstrap form. Which CSS snippet achieves this without affecting mouse users?
Bootsrap
<form> <button type="submit" class="btn btn-primary">Submit</button> <button type="button" class="btn btn-secondary">Cancel</button> </form>
Attempts:
2 left
💡 Hint
Focus-visible applies only when keyboard navigation triggers focus.
✗ Incorrect
The :focus-visible pseudo-class shows the outline only when the user navigates via keyboard, avoiding distracting outlines for mouse users.
🧠 Conceptual
advancedARIA roles and keyboard navigation in Bootstrap tabs
In a Bootstrap tab component, which ARIA role and keyboard behavior combination ensures proper keyboard navigation between tabs?
Bootsrap
<ul class="nav nav-tabs" role="tablist"> <li class="nav-item" role="presentation"> <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button> </li> <li class="nav-item" role="presentation"> <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button> </li> </ul>
Attempts:
2 left
💡 Hint
ARIA roles must match the tab pattern for screen readers and keyboard users.
✗ Incorrect
Bootstrap tabs use role="tablist" on the container and role="tab" on each tab button. Arrow keys are used to move focus between tabs for accessibility.
📝 Syntax
expertJavaScript keyboard event handling for Bootstrap dropdown
Which JavaScript snippet correctly listens for keyboard events to open a Bootstrap dropdown menu when the user presses Enter or Space on the toggle button?
Bootsrap
<div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown button </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> </ul> </div>
Attempts:
2 left
💡 Hint
Check event type, key names, and how to toggle dropdown with Bootstrap's JS API.
✗ Incorrect
Option A uses 'keydown' event, checks for 'Enter' or space (' '), prevents default, and toggles the dropdown by creating a new instance. This is the correct way to handle keyboard activation for Bootstrap dropdown toggles.
