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

Add body class when loaded - fix #8 #50

Merged
merged 1 commit into from
Aug 10, 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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ in situations in which the `:focus-ring` pseudo-selector should match.

We suggest that users
selectively disable the default focus style
by selecting for the case when `.focus-ring` is _not_ applied:
by selecting for the case when the polyfill is loaded
and `.focus-ring` is _not_ applied to the element:

```html
:focus:not(.focus-ring) {
.focus-ring-enabled :focus:not(.focus-ring) {
outline-width: 0;
}
```
Expand Down Expand Up @@ -134,9 +135,12 @@ 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` class on the active element
It simply sets a `.focus-ring-enabled` class to 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.
This attribute is removed on any `blur` event.

This allows authors to write rules
which show a focus style only when it would be relevant to the user.
Note that the prototype does not match the proposed API -
Expand Down
12 changes: 7 additions & 5 deletions dist/focus-ring.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ function init() {
* to which it was previously applied.
*/
function onWindowFocus() {
if (document.activeElement == elWithFocusRing) {
if (document.activeElement == elWithFocusRing)
addFocusRingClass(elWithFocusRing);
elWithFocusRing = null;
}

elWithFocusRing = null;
}

/**
* When the window regains focus, restore the focus-ring class to the element
* to which it was previously applied.
* When switching windows, keep track of the focused element if it has a
* focus-ring class.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These JSDOC changes are not intended by me. It seems like the docs in the dist file were not up to date. Now they're matching with the docs in src.

function onWindowBlur() {
if (document.activeElement.classList.contains('focus-ring')) {
Expand All @@ -312,6 +312,8 @@ function init() {
document.addEventListener('blur', onBlur, true);
window.addEventListener('focus', onWindowFocus, true);
window.addEventListener('blur', onWindowBlur, true);

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

/**
Expand Down
2 changes: 2 additions & 0 deletions src/focus-ring.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ function init() {
document.addEventListener('blur', onBlur, true);
window.addEventListener('focus', onWindowFocus, true);
window.addEventListener('blur', onWindowBlur, true);

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

/**
Expand Down