fix: restore keyboard focus after clearing whitelist#76
Conversation
Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses an accessibility issue in the extension popup where keyboard focus is lost (falls back to body) after clearing the whitelist, by explicitly restoring focus after the list re-renders.
Changes:
- Update
clearDomainsinpopup.jsto focus#add-domainafterrenderList()completes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await browser.storage.sync.set({ [STORAGE_KEY]: [] }); | ||
| setStatus("Liste blanche vidée."); | ||
| await renderList(); | ||
| document.getElementById("add-domain").focus(); |
There was a problem hiding this comment.
#add-domain can be disabled when no current domain is detected (initPopup sets addButton.disabled = true). Calling .focus() on a disabled button is a no-op, so focus may still drop to body in exactly the scenarios where accessibility is already degraded (e.g., internal pages). Consider checking add-domain exists and is not disabled before focusing it, and otherwise moving focus to another enabled control (e.g., #clear-domains) or making the status region programmatically focusable as a fallback.
| document.getElementById("add-domain").focus(); | |
| const addButton = document.getElementById("add-domain"); | |
| if (addButton && !addButton.disabled) { | |
| addButton.focus(); | |
| } else { | |
| const clearButton = document.getElementById("clear-domains"); | |
| if (clearButton && !clearButton.disabled) { | |
| clearButton.focus(); | |
| } else { | |
| const statusRegion = document.getElementById("status"); | |
| if (statusRegion) { | |
| if (!statusRegion.hasAttribute("tabindex")) { | |
| statusRegion.setAttribute("tabindex", "-1"); | |
| } | |
| statusRegion.focus(); | |
| } | |
| } | |
| } |
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: ormidales <46538211+ormidales@users.noreply.github.com>
Applied in b914da5. The focus logic in |
document.getElementById("add-domain").focus()afterawait renderList()inclearDomainsinpopup.jsnode --check#add-domain, fall back to#clear-domains, then#statusregionOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.