Accessibility util for storing/restoring focus.
JavaScript
Switch branches/tags
Nothing to show
Clone or download
jwineman Merge pull request #1 from Haroenv/patch-1
chore(package): add git repo
Latest commit c35d3ea Feb 22, 2017
Permalink
Failed to load latest commit information.
.gitignore Init commit Nov 12, 2015
LICENSE Init commit Nov 12, 2015
README.md Init commit Nov 12, 2015
index.js Init commit Nov 12, 2015
karma.conf.js Init commit Nov 12, 2015
package.json chore(package): add git repo Feb 22, 2017
test.js Init commit Nov 12, 2015

README.md

a11y-focus-store

Accessibility util for storing/restoring focus.

Installation

$ npm install --save a11y-focus-store

Usage

import {storeFocus, restoreFocus, clearStoredFocus} from 'a11y-focus-store';

document.body.innerHTML = `
  <button id="button-1">Button 1</button>
  <button id="button-2">Button 2</button>
  <button id="button-3">Button 3</button>
`;

var button1 = document.getElementById('button-1');
var button2 = document.getElementById('button-2');
var button3 = document.getElementById('button-3');

button1.focus();
storeFocus();

button2.focus();
restoreFocus();
// document.activeElement === button1;

button1.focus();
storeFocus();
clearStoredFocus();

innerButton.focus();
// document.activeElement === innerButton;

outerButton.focus();
// document.activeElement === container;

unscopeFocus();
outerButton.focus();
// document.activeElement === outerButton;