Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #14867 - Tab change inkbar for material design theme #14895

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/app/components/tabmenu/tabmenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,28 @@ describe('TabMenu', () => {
expect(itemClickSpy).toHaveBeenCalled();
});

it('should select item when activeItem controlled', () => {
tabmenu.model = [
{ label: 'Stats', icon: 'pi pi-fw pi-bar-chart' },
{ label: 'Calendar', icon: 'pi pi-fw pi-calendar' },
{ label: 'Documentation', icon: 'pi pi-fw pi-book' },
{ label: 'Support', icon: 'pi pi-fw pi-support' },
{ label: 'Social', icon: 'pi pi-fw pi-twitter' }
];

const updateInkBarSpy = spyOn(tabmenu, 'updateInkBar').and.callThrough();

tabmenu.activeItem = tabmenu.model[1];
fixture.detectChanges();

const itemList = fixture.debugElement.query(By.css('ul'));

expect(itemList.children[1].nativeElement.className).toContain('p-highlight');
expect(tabmenu.activeItem.label).toEqual('Calendar');
expect(tabmenu.activeItem.icon).toContain('pi-calendar');
expect(updateInkBarSpy).toHaveBeenCalled();
});

it("shouldn't show content", () => {
tabmenu.model = [
{ label: 'Stats', icon: 'pi pi-fw pi-bar-chart', disabled: true },
Expand Down
14 changes: 12 additions & 2 deletions src/app/components/tabmenu/tabmenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,15 @@ export class TabMenu implements AfterContentInit, AfterViewInit, AfterViewChecke
* Defines the default active menuitem
* @group Props
*/
@Input() activeItem: MenuItem | undefined;
@Input() set activeItem(value: MenuItem | undefined) {
this._activeItem = value;
this.activeItemChange.emit(value);
this.tabChanged = true;
}

get activeItem(): MenuItem | undefined {
return this._activeItem;
}
/**
* When enabled displays buttons at each side of the tab headers to scroll the tab list.
* @group Props
Expand Down Expand Up @@ -221,6 +229,8 @@ export class TabMenu implements AfterContentInit, AfterViewInit, AfterViewChecke

_model: MenuItem[] | undefined;

_activeItem: MenuItem | undefined;

focusedItemInfo = signal<any>(null);

get focusableItems() {
Expand Down Expand Up @@ -267,7 +277,7 @@ export class TabMenu implements AfterContentInit, AfterViewInit, AfterViewChecke
}

ngAfterViewChecked() {
if (this.tabChanged) {
if (isPlatformBrowser(this.platformId) && this.tabChanged) {
this.updateInkBar();
this.tabChanged = false;
}
Expand Down