Skip to content

Commit

Permalink
fix(supports): reset scroll position of <body> element - #60
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Jan 28, 2016
1 parent 3f9af38 commit c32930c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/supports/detect-focus.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function detectFocus(options) {
// remember scroll positions to restore after test
const previousScrollTop = window.scrollTop;
const previousScrollLeft = window.scrollLeft;
const previousBodyScrollTop = document.body.scrollTop;
const previousBodyScrollLeft = document.body.scrollLeft;
// test if the element with invalid tabindex can be focused
focus.focus && focus.focus();
// validate test's result
Expand All @@ -39,6 +41,8 @@ function detectFocus(options) {
// restore scroll position
window.scrollTop !== previousScrollTop && (window.scrollTop = previousScrollTop);
window.scrollLeft !== previousScrollLeft && (window.scrollLeft = previousScrollLeft);
document.body.scrollTop !== previousBodyScrollTop && (document.body.scrollTop = previousBodyScrollTop);
document.body.scrollLeft !== previousBodyScrollLeft && (document.body.scrollLeft = previousBodyScrollLeft);
return allowsFocus;
}

Expand Down

0 comments on commit c32930c

Please sign in to comment.