scrollIntoView doesn't work properly for some cases
See original GitHub issueHi there,
I found one issue with the API call - scrollIntoView
. For my case, it works most time with a small tree, but does not work for the large tree. So I created my own local function based on the source code
below.
TreeNode.prototype.scrollIntoView = function () {
if (this.elementRef) {
var nativeElement = this.elementRef.nativeElement;
nativeElement.scrollIntoViewIfNeeded && nativeElement.scrollIntoViewIfNeeded();
return this;
}
};
I am using scrollIntoView
instead of scrollIntoViewIfNeeded
, which is also suggested by
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded
My code:
if (this.focusedNode) {
if (this.focusedNode.elementRef) {
let nativeElement = this.focusedNode.elementRef.nativeElement;
nativeElement.scrollIntoView();
}
};
It works for both small and large trees.
I hope my finding and solution will be helpful to others.
Best
-John
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top Results From Across the Web
scrollIntoView() doesn't scroll anywhere
I was facing the same issue. scrollIntoView was working only if behavior was auto . Setting a delay fixed some cases but not...
Read more >Unfortunately scrollIntoView doesn't seem to behave ...
Linux (latest version of KDE): it doesn't work properly. The carousel view is scrolled to the top of the view port, but the...
Read more >scroll-into-view-if-needed
Start using scroll-into-view-if-needed in your project by running `npm i ... on what is the most important to your use case:: load time, ......
Read more >42593 – element.scrollIntoView() sometimes doesn't scroll
There's an issue open about focus() on the W3C bug tracker [1]. Firefox has another behavior where it decided whether or not to...
Read more >scrollIntoView issue with vue-router - Hi - Bong's Notes
After googling, it looks like vue-router doesn't work well with scrollTo and sticky div element (link). And I use sticky for my sidebar....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve got the same issue. scrollIntoView works in Firefox and IE11 for my application, but not in Chrome. I can’t seem to reproduce a working example to show here though.
Here is a broken example where scrollIntoView doesn’t work in any browser I’ve tried with.
It did the trick. Thanks!