Skip to content

Commit

Permalink
feat(material/tabs): add API to update the pagination (#23288)
Browse files Browse the repository at this point in the history
We try to update the pagination state of the tab group very sparingly, because it has performance implications. This means that we may miss some updates.

These changes expose a method so that consumers can trigger a recalculation on their own.

Fixes #23206.
  • Loading branch information
crisbeto committed Jan 15, 2022
1 parent b851456 commit b9a3908
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/material/tabs/tab-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ const _MatTabGroupMixinBase = mixinColor(
);

interface MatTabGroupBaseHeader {
_alignInkBarToSelectedTab: () => void;
_alignInkBarToSelectedTab(): void;
updatePagination(): void;
focusIndex: number;
}

Expand Down Expand Up @@ -327,6 +328,19 @@ export abstract class _MatTabGroupBase
}
}

/**
* Recalculates the tab group's pagination dimensions.
*
* WARNING: Calling this method can be very costly in terms of performance. It should be called
* as infrequently as possible from outside of the Tabs component as it causes a reflow of the
* page.
*/
updatePagination() {
if (this._tabHeader) {
this._tabHeader.updatePagination();
}
}

/**
* Sets focus to a particular tab.
* @param index Index of the tab to be focused.
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements
// (undocumented)
abstract _tabHeader: MatTabGroupBaseHeader;
_tabs: QueryList<MatTab>;
updatePagination(): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<_MatTabGroupBase, never, never, { "dynamicHeight": "dynamicHeight"; "selectedIndex": "selectedIndex"; "headerPosition": "headerPosition"; "animationDuration": "animationDuration"; "contentTabIndex": "contentTabIndex"; "disablePagination": "disablePagination"; "backgroundColor": "backgroundColor"; }, { "selectedIndexChange": "selectedIndexChange"; "focusChange": "focusChange"; "animationDone": "animationDone"; "selectedTabChange": "selectedTabChange"; }, never>;
// (undocumented)
Expand Down

0 comments on commit b9a3908

Please sign in to comment.