Skip to content

Commit

Permalink
fix(dropdown): fix scrollActiveOptionIntoView for dropdown with many …
Browse files Browse the repository at this point in the history
…groups (#1182)
  • Loading branch information
[email protected] authored and GitHub Enterprise committed May 2, 2024
1 parent 4f88a99 commit b63fb68
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions projects/ng-aquila/src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,20 +906,7 @@ export class NxDropdownComponent

const activeItem = this._keyManager.activeItem.containerElement.nativeElement;
this.liveAnnouncer.announce(activeItem.textContent); // force screen reader to speak active option
const panel = this.panelBody.nativeElement;
const panelOffset = panel.offsetTop; // how much the overlay is repositioned on the page
const panelTopScrollPosition = panel.scrollTop;
const panelHeight = panel.clientHeight;
const itemTop = activeItem.offsetTop - panelOffset;
const itemBottom = activeItem.offsetTop - panelOffset + activeItem.getBoundingClientRect().height;

// item half or less visible on top
if (itemTop < panelTopScrollPosition) {
this.panelBody.nativeElement.scrollTop = itemTop;
// item half or less visible on bottom
} else if (itemBottom > panelTopScrollPosition + panelHeight) {
this.panelBody.nativeElement.scrollTop = itemBottom - panelHeight;
}
activeItem.scrollIntoView({ block: 'nearest' });
}

private _getItemOffset(item: NxDropdownItemComponent | null): number {
Expand Down

0 comments on commit b63fb68

Please sign in to comment.