Skip to content

Commit

Permalink
fix(material/tabs): ink bar not showing when same tab is re-selected (#…
Browse files Browse the repository at this point in the history
…30121)

Fixes that if a tab is active, it gets cleared and the re-selected, the ink bar wasn't showing up.

Fixes #30036.
  • Loading branch information
crisbeto authored Dec 4, 2024
1 parent 8a55d9a commit a028b5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/material/tabs/ink-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class MatInkBar {
/** Hides the ink bar. */
hide() {
this._items.forEach(item => item.deactivateInkBar());
this._currentItem = undefined;
}

/** Aligns the ink bar to a DOM node. */
Expand Down
22 changes: 22 additions & 0 deletions src/material/tabs/tab-nav-bar/tab-nav-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,28 @@ describe('MatTabNavBar', () => {
expect(tabLinks[1].classList.contains('mdc-tab--active')).toBe(true);
});

it('should re-show the ink bar if the same tab is cleared and re-activated', fakeAsync(() => {
const getInkBars = () =>
fixture.nativeElement.querySelectorAll('.mdc-tab-indicator--active').length;
const fixture = TestBed.createComponent(SimpleTabNavBarTestApp);
fixture.componentInstance.activeIndex = 0;
fixture.detectChanges();
tick(20);
expect(getInkBars()).toBe(1);

fixture.componentInstance.activeIndex = -1;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
tick(20);
expect(getInkBars()).toBe(0);

fixture.componentInstance.activeIndex = 0;
fixture.changeDetectorRef.markForCheck();
fixture.detectChanges();
tick(20);
expect(getInkBars()).toBe(1);
}));

describe('ripples', () => {
let fixture: ComponentFixture<SimpleTabNavBarTestApp>;

Expand Down

0 comments on commit a028b5d

Please sign in to comment.