#Any cleaner way of bringing scroller to top in ng-select multiselect

6 messages · Page 1 of 1 (latest)

uncut steppe
#

I have a multiselect dropdown created with ng-select. I'm trying to bring the scroller to top when multiple items are selected. It seems to bring the scroller to position such that last multi selected item is visible in the dropdown. Examples are shown https://ng-select.github.io/ng-select#/data-sources

I tried something ugly like this with a setTimeout. Not a fan of using setTimeout 😕
Any cleaner way of doing this? Have I missed a prop which does this for me ?

here is a reproducible demo https://stackblitz.com/edit/angular-kqzedb-p1lz6r?file=src%2Fmulti-select-default-example.component.html

<ng-select ...
(open)="onMyDropdownOpen()"
@ViewChild(NgSelectComponent) myDropdown!: NgSelectComponent;

  onMyDropdownOpen(): void {
    setTimeout(() => {
      if (this.myDropdown?.dropdownPanel) {
        this.myDropdown.dropdownPanel.scrollElementRef.nativeElement.scrollTop = 0;
      }      
    }, 0);    
  }
wary wyvern
uncut steppe
uncut steppe
# wary wyvern It seems to be a long time request, that should have been fixed. Then reverted. ...

i created a new discussion and referenced it in this issue. https://github.com/ng-select/ng-select/discussions/2363

what do you think of the setTimeout approach. Do you think it would lead to bugs thin_cat

GitHub

I have a multiselect dropdown created with ng-select. I'm trying to bring the scroller to top when multiple items are selected. It seems to bring the scroller to position such that last multi s...

wary wyvern
#

Playing with macrotask is something I don't like too much.
Btw, I don't know why you opened that as discussion instead that as an issue.

uncut steppe
#

issues have to be selected as bug fix or feature requests. wasn't sure if this was a bug or a missing feature