Skip to content

Commit

Permalink
fix(supports): restore scroll position after tests - #60
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Dec 6, 2015
1 parent 201eb3a commit fa9a740
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/supports/detect-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function detectFocus(options) {
!element.parentNode && wrapper.appendChild(element);
// remember what had focus to restore after test
const previousActiveElement = document.activeElement;
// remember scroll positions to restore after test
const previousScrollTop = window.scrollTop;
const previousScrollLeft = window.scrollLeft;
// test if the element with invalid tabindex can be focused
focus.focus && focus.focus();
// validate test's result
Expand All @@ -33,6 +36,9 @@ function detectFocus(options) {
document.activeElement && document.activeElement.blur();
previousActiveElement && previousActiveElement.focus() || document.body.focus();
document.body.removeChild(wrapper);
// restore scroll position
window.scrollTop !== previousScrollTop && (window.scrollTop = previousScrollTop);
window.scrollLeft !== previousScrollLeft && (window.scrollLeft = previousScrollLeft);
return allowsFocus;
}

Expand Down

0 comments on commit fa9a740

Please sign in to comment.