Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename class to .js-focus-ring and update readme #51

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ by selecting for the case when the polyfill is loaded
and `.focus-ring` is _not_ applied to the element:

```html
.focus-ring-enabled :focus:not(.focus-ring) {
.js-focus-ring :focus:not(.focus-ring) {
outline-width: 0;
}
```
Expand Down Expand Up @@ -124,8 +124,9 @@ having both would provide more flexibility for authors.

The heuristic used to decide the current modality should not be defined
normatively. An example heuristic is to update modality on each style recalc:
if the most recent user interaction was via the keyboard; and less than 100ms
has elapsed since the last input event; then the modality is keyboard. Otherwise,
if the most recent user interaction was via the keyboard;
and the key pressed was either `Tab` or `Shift + Tab`;
then the modality is keyboard. Otherwise,
the modality is not keyboard.

## Implementation Prototype
Expand All @@ -135,7 +136,7 @@ The tiny
provides a prototype intended to achieve the goals we are proposing
with technology that exists today
in order for developers to be able to try it out, understand it and provide feedback.
It simply sets a `.focus-ring-enabled` class to the body element
It sets a `.js-focus-ring` class on the body element
to provide a way to disable focus styles only when the polyfill is loaded.
It also sets a `.focus-ring` class on the active element
if the script determines that the keyboard is being used.
Expand All @@ -150,7 +151,8 @@ rather than to provide a high-fidelity polyfill.
### How it works
The script uses two heuristics to determine whether the keyboard is being used:

- a `focus` event immediately following a `keydown` event
- a `focus` event immediately following a `keydown` event where the key pressed was either `Tab`
or `Shift + Tab`.
- focus moves into an element which requires keyboard interaction,
such as a text field
- _TODO: ideally, we also trigger keyboard modality
Expand Down
2 changes: 1 addition & 1 deletion src/focus-ring.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function init() {
window.addEventListener('focus', onWindowFocus, true);
window.addEventListener('blur', onWindowBlur, true);

document.body.classList.add('focus-ring-enabled');
document.body.classList.add('js-focus-ring');
}

/**
Expand Down