Skip to content

Commit

Permalink
Avoid flash effect on scroll restoration (#25)
Browse files Browse the repository at this point in the history
* Move nativeFocus execution as close as possible to scroll restoration

* Increase package minor version
  • Loading branch information
calvellido committed Sep 5, 2020
1 parent 6f32aaf commit 321a392
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -79,13 +79,15 @@
var patchedFocus = function(args) {
if (args && args.preventScroll) {
var evScrollableElements = calcScrollableElements(this);
this.nativeFocus();
if (typeof setTimeout === 'function') {
var thisElem = this;
setTimeout(function () {
thisElem.nativeFocus();
restoreScrollPosition(evScrollableElements);
}, 0);
} else {
restoreScrollPosition(evScrollableElements);
this.nativeFocus();
restoreScrollPosition(evScrollableElements);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "focus-options-polyfill",
"version": "1.5.1",
"version": "1.6.0",
"description": "JavaScript polyfill for the WHATWG spec of focusOptions, that enables a set of options to be passed to the focus method.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 321a392

Please sign in to comment.