a11y-focus-store
Version:
Accessibility util for storing/restoring focus.
18 lines (13 loc) • 354 B
JavaScript
;
var storedFocusElement;
exports.storeFocus = function() {
storedFocusElement = document.activeElement;
};
exports.clearStoredFocus = function() {
storedFocusElement = null;
};
exports.restoreFocus = function() {
if (!storedFocusElement) return;
try { storedFocusElement.focus(); } catch (err) {}
storedFocusElement = null;
};