Skip to content

Commit

Permalink
Merge pull request #351 from StefKors/native-scrollInfoView
Browse files Browse the repository at this point in the history
Use native scrollIntoView method so it correctly accounts for paddings and scroll-margins
  • Loading branch information
csculley committed Nov 2, 2023
2 parents ce38aea + 3d39ec6 commit f2801f2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quill-mention",
"version": "4.0.1",
"version": "4.1.0",
"description": "@mentions for the Quill rich text editor",
"homepage": "https://quill-mention.com/",
"main": "dist/quill.mention.csj.js",
Expand Down
18 changes: 4 additions & 14 deletions src/quill.mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,10 @@ class Mention {
);

if (scrollItemInView) {
const itemHeight =
this.mentionList.childNodes[this.itemIndex].offsetHeight;
const itemPos = this.mentionList.childNodes[this.itemIndex].offsetTop;
const containerTop = this.mentionContainer.scrollTop;
const containerBottom = containerTop + this.mentionContainer.offsetHeight;

if (itemPos < containerTop) {
// Scroll up if the item is above the top of the container
this.mentionContainer.scrollTop = itemPos;
} else if (itemPos > containerBottom - itemHeight) {
// scroll down if any part of the element is below the bottom of the container
this.mentionContainer.scrollTop +=
itemPos - containerBottom + itemHeight;
}
this.mentionList.childNodes[this.itemIndex].scrollIntoView({
behaviour: "smooth",
block: "nearest",
});
}
}

Expand Down

0 comments on commit f2801f2

Please sign in to comment.