Skip to content

Commit

Permalink
fix(dropdown): no scrolling or highlighting of the selected option if…
Browse files Browse the repository at this point in the history
… list not loaded before (#1166)
  • Loading branch information
[email protected] authored and GitHub Enterprise committed Apr 15, 2024
1 parent 5ad6feb commit 54aa4f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions projects/ng-aquila/src/dropdown/dropdown.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,17 @@ describe('NxDropdownComponent', () => {
// 4 * 44 + 22 (half of item height) + 12 (firstItemPaddingTop) - 100 (middle of panel)
expect(dropdownInstance.panelBody?.nativeElement.scrollTop).toBe(110);
}));

it('should scroll the selected item in the middle of the panel on dropdown change', fakeAsync(() => {
createTestComponent(ScrollingTestComponent);
trigger.click();
tick(500);
flush();
fixture.detectChanges();
tick(1);
// 4 * 44 + 22 (half of item height) + 12 (firstItemPaddingTop) - 100 (middle of panel)
expect(dropdownInstance.panelBody?.nativeElement.scrollTop).toBe(110);
}));
});

describe('multiselect dropdown', () => {
Expand Down
3 changes: 3 additions & 0 deletions projects/ng-aquila/src/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ export class NxDropdownComponent
// the combination of dropdown-item notifying parent and when the parent
// tries to fetch the triggerValue from the child throws these errors
setTimeout(() => {
if (this._panelOpen) {
this._initActiveItem();
}
this._cdr.markForCheck();
this.stateChanges.next();
});
Expand Down

0 comments on commit 54aa4f4

Please sign in to comment.