Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native scrollIntoView method so it correctly accounts for paddings and scroll-margins #351

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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