https://github.com/cdata/focus-observer
Observe focus changes throughout the document, with support for ShadowDOM
https://github.com/cdata/focus-observer
Last synced: 10 months ago
JSON representation
Observe focus changes throughout the document, with support for ShadowDOM
- Host: GitHub
- URL: https://github.com/cdata/focus-observer
- Owner: cdata
- License: mit
- Created: 2015-04-11T03:55:37.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-13T18:22:07.000Z (almost 11 years ago)
- Last Synced: 2025-02-02T00:32:00.776Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 102 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## FocusObserver
With the introduction of ShadowDOM, tracking active focus elements on the page
for the purposes of accessibility features has been complicated. `FocusObserver`
is intended to simplify observation of focus changes that span the full depth of
the accessibility tree, including parts of the tree within shadow roots.
### Usage
`FocusObserver` has an interface that is modeled after `MutationObserver`.
```javascript
var focusObserver = new FocusObserver(function onFocus(event) {
console.log('The current active element is', event.activeElement);
console.log('The active element\'s root is', event.activeRoot);
console.log('The active element\'s host is', event.activeHost):
});
// Connect the focus observer..
focusObserver.observe();
// Disconnect the focus observer..
focusObserver.disconnect();
```