Skip to content

Commit

Permalink
fix(material/tabs): remove visibility style when hydrating
Browse files Browse the repository at this point in the history
Before this commit, when using pre-rendering, the styling animation would only remove the `transform` style when hydrating the component. This commit fixes this by including `visibility` as styles to remove when playing the animations.
  • Loading branch information
JeanMeche committed Jun 9, 2024
1 parent 35f07c5 commit b5c5bf4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/material/tabs/tab-group.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {LEFT_ARROW, RIGHT_ARROW} from '@angular/cdk/keycodes';
import {dispatchFakeEvent, dispatchKeyboardEvent} from '@angular/cdk/testing/private';
import {CommonModule} from '@angular/common';
import {
Component,
DebugElement,
Expand All @@ -11,15 +12,14 @@ import {
} from '@angular/core';
import {
ComponentFixture,
TestBed,
fakeAsync,
flush,
TestBed,
tick,
waitForAsync,
} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
import {CommonModule} from '@angular/common';
import {Observable} from 'rxjs';
import {
MAT_TABS_CONFIG,
Expand Down Expand Up @@ -772,7 +772,7 @@ describe('MDC-based MatTabGroup', () => {
);

expect(contentElements.map(element => element.style.visibility)).toEqual([
'',
'visible',
'hidden',
'hidden',
'hidden',
Expand All @@ -785,7 +785,7 @@ describe('MDC-based MatTabGroup', () => {
expect(contentElements.map(element => element.style.visibility)).toEqual([
'hidden',
'hidden',
'',
'visible',
'hidden',
]);

Expand All @@ -795,7 +795,7 @@ describe('MDC-based MatTabGroup', () => {

expect(contentElements.map(element => element.style.visibility)).toEqual([
'hidden',
'',
'visible',
'hidden',
'hidden',
]);
Expand Down
7 changes: 5 additions & 2 deletions src/material/tabs/tabs-animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {
AnimationTriggerMetadata,
animate,
state,
style,
transition,
trigger,
AnimationTriggerMetadata,
} from '@angular/animations';

/**
Expand All @@ -24,7 +24,10 @@ export const matTabsAnimations: {
/** Animation translates a tab along the X axis. */
translateTab: trigger('translateTab', [
// Transitions to `none` instead of 0, because some browsers might blur the content.
state('center, void, left-origin-center, right-origin-center', style({transform: 'none'})),
state(
'center, void, left-origin-center, right-origin-center',
style({transform: 'none', visibility: 'visible'}),
),

// If the tab is either on the left or right, we additionally add a `min-height` of 1px
// in order to ensure that the element has a height before its state changes. This is
Expand Down

0 comments on commit b5c5bf4

Please sign in to comment.