ngx-mat-select-search icon indicating copy to clipboard operation
ngx-mat-select-search copied to clipboard

[BUG] scrolling using Page Up and Home does not scroll all the way to the top

Open paulflo150 opened this issue 2 years ago • 4 comments

Describe the bug Using Home or Page Up to scroll does not seem to take into consideration the sticky element, so it will only scroll to the top of the actual list of options, which leaves the very first element of the list hidden under the search. Any ideas on how to get this fixed?

To Reproduce You can see it in the example provided.

paulflo150 avatar Feb 21 '23 11:02 paulflo150

thanks for reporting this issue. do you want to try to find a fix?

macjohnny avatar Feb 21 '23 16:02 macjohnny

How about something like this?

` _handleKeydown(event: KeyboardEvent) {
//existing code.

if (event.key === 'PageUp' || event.key === 'PageDown') {
  const panel = this.matSelect.panel.nativeElement;

  const left = panel.scrollLeft;
  const top = panel.scrollTop;

  const delta = panel.scrollHeight - 32 * 5;

  event.key === 'PageUp' ? panel.scrollTo(left, top - delta) : panel.scrollTo(left, top + delta);
  
  event.preventDefault();
}

if (event.key === 'Home' || event.key === 'End') {
  const panel = this.matSelect.panel.nativeElement;
  event.key === 'Home' ? panel.scrollTo(0, 0) : panel.scrollTo(0, panel.scrollHeight);

  event.preventDefault();
}

} `

paulflo150 avatar Feb 21 '23 21:02 paulflo150

I havent tested that, but do you want to create a PR and test that this works properly?

macjohnny avatar Feb 22 '23 16:02 macjohnny

@paulflo150 would you like to prepare a PR?

macjohnny avatar Mar 18 '23 07:03 macjohnny