Modal dialog has no focus trap
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- accessibility, frontend
Research direction
Start in assets/js/modal.js, especially the custom Escape handler at lines 60–64 and the open and close paths. Check how the 400ms animation delay interacts with dialog.close() and focus. Done means keyboard focus remains managed during closing and returns to the element that triggered the modal after it closes.
Written by the indexing model from the issue text.
Description
Summary
The site uses a native HTML <dialog> element with showModal(), which provides some built-in accessibility behaviour. However, the current implementation in modal.js overrides the native Escape key handler without ensuring focus is properly managed, and focus can potentially escape the modal to the background content depending on browser/AT combinations.
Affected location
assets/js/modal.js
Details
Native <dialog> with showModal() does implement a focus trap in modern browsers. However:
- The custom Escape key handler in
modal.js:60–64callscloseModal()which uses a CSS animation delay of 400ms before callingdialog.close(). During this window, the dialog is visually closing but still open in the DOM, which can cause focus confusion. - Focus is not explicitly returned to the trigger element that opened the modal after it closes — it falls back to the browser default (usually
<body>).
Fix
After calling modal.close(), return focus to the element that triggered the modal:
// Track the trigger element when opening
const openModal = (modal) => {
modal._trigger = document.activeElement; // store trigger
// ... existing open logic
modal.showModal();
};
const closeModal = (modal) => {
const trigger = modal._trigger;
// ... existing close logic (with animation timeout)
setTimeout(() => {
// ... existing cleanup
modal.close();
if (trigger) trigger.focus(); // return focus to trigger
}, animationDuration);
};
WCAG criterion
2.1.2 No Keyboard Trap (Level A), 2.4.3 Focus Order (Level A)
- Dominant language
- HTML
- Stars
- 1
- Forks
- 6
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from CivicTechTO/civictech.ca
-
accessibility
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
CivicTechTO/civictech.ca#192 ·
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
CivicTechTO/civictech.ca#189 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
CivicTechTO/civictech.ca#186 ·
-
accessibility
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
CivicTechTO/civictech.ca#184 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
CivicTechTO/civictech.ca#101 ·
All issues in CivicTechTO/civictech.ca
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
deltachat/deltachat-ios#3411 · 1 reaction ·
Maintainers usually reply within 1 day
-
affecting 5.2 only affecting 5.3 only bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
moodle-an-hochschulen/moodle-theme_boost_union#1463 ·
Maintainers usually reply within 1 day
-
[Bug]: SQL cells cannot be opened with the keyboardPossibly taken @thc1006 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
jaegertracing/jaeger-ui#4657 ·
Maintainers usually reply within 2 days
-
UI/UX improvementsOpenenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dnerever/OpenRecipe#73 ·
Maintainers usually reply within 1 day
-
a10y a10y-audit ai-driven-qa claude
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
linagora/twake-directory-manager#219 ·
Maintainers usually reply within 1 day