Last active
August 29, 2015 14:24
-
-
Save bkardell/d444e006bd6cfbc99986 to your computer and use it in GitHub Desktop.
An experiment in effectively managing focus rings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", function () { | |
document.body.addEventListener("mousedown", function (evt) { | |
if (!evt.target.setSelectionRange || evt.target.role === 'textbox' || evt.target.hasAttribute("disable-point-focus")) { | |
evt.target.setAttribute("point-focused", true); | |
} | |
}); | |
document.body.addEventListener("blur", function (evt) { | |
evt.srcElement.removeAttribute("point-focused"); | |
}, true); | |
}); |
Showing more of the focus rings for those who need them (keyboard users) is the right thing. I like that the mouse user is seeing less of them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on a conversation with Alice Boxhall and Marcy Sutton, this snippet attaches/manages metadata in the form of an attribute to an element whose focus has been set via a pointing device rather than the keyboard unless:
* It has
setSelectionRange
method, because things you can type are different* It has an aria role of textbox, so artificial elements that get the aria right should still work
* is has an attribute 'disable-point-focus' so that it is simple to create an opt-out for custom elements/constructs
Should enable simple focus rules that meet the spirit of a11y guidelines for keyboard users but don't get in the way for pointer users.
Note, I have some philosophical problems with this (as a mixed user myself, I always like to see the focus ring in order to help my understanding of my context in the document) but I appear to be in the minority and improving the status quo (which is bad) requires someone to suggest change - so here it is...