Skip to content

Commit

Permalink
don't use scrollIntoView
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Aug 20, 2021
1 parent 8335311 commit 98287b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap5-tags",
"version": "1.1.3",
"version": "1.1.4",
"description": "Replace select[multiple] with nices badges",
"main": "bootstrap5-tags",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class Tags {
}
active.classList.remove(...ACTIVE_CLASSES);
prev.querySelector("a").classList.add(...ACTIVE_CLASSES);
prev.scrollIntoView(true);
// Don't use scrollIntoView as it scrolls the whole window
prev.parentNode.scrollTop = prev.offsetTop - prev.parentNode.offsetTop;
return prev;
}
return null;
Expand All @@ -235,7 +236,10 @@ class Tags {
}
active.classList.remove(...ACTIVE_CLASSES);
next.querySelector("a").classList.add(...ACTIVE_CLASSES);
next.scrollIntoView(false);
// This is the equivalent of scrollIntoView(false) but only for parent node
if (next.offsetTop > next.parentNode.offsetHeight - next.offsetHeight) {
next.parentNode.scrollTop += next.offsetHeight;
}
return next;
}
return null;
Expand Down Expand Up @@ -376,7 +380,7 @@ class Tags {
this.holderElement.classList.remove("is-invalid");
}
firstItem.querySelector("a").classList.add(...ACTIVE_CLASSES);
firstItem.scrollIntoView();
firstItem.parentNode.scrollTop = firstItem.offsetTop - firstItem.parentNode.offsetTop;
} else {
// No item and we don't allow new items => error
if (!this.allowNew && !(search.length === 0 && !hasPossibleValues)) {
Expand Down
2 changes: 1 addition & 1 deletion tags.min.js

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

0 comments on commit 98287b3

Please sign in to comment.