Skip to content

Commit 58d3bb8

Browse files
crisbetokara
authored andcommitted
fix(snack-bar): positioned snack bar animation not starting off-screen (#7453)
1 parent 00e9338 commit 58d3bb8

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/lib/snack-bar/snack-bar-container.scss

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@ $mat-snack-bar-spacing-margin: 24px !default;
1515
min-width: $mat-snack-bar-min-width;
1616
padding: $mat-snack-bar-padding;
1717
// Initial transformation is applied to start snack bar out of view, below its target position.
18-
transform: translateY(100%);
18+
// Note: it's preferred to use a series of transforms, instead of something like `calc()`, because
19+
// IE won't animate transforms that contain a `calc`.
20+
transform: translateY(100%) translateY($mat-snack-bar-spacing-margin);
1921

20-
/**
22+
/**
2123
* Removes margin of snack bars which are center positioned horizontally. This
2224
* is done to align snack bars to the edge of the view vertically to match spec.
2325
*/
2426
&.mat-snack-bar-center {
2527
margin: 0;
28+
transform: translateY(100%);
2629
}
2730

2831
/**
2932
* To allow for animations from a 'top' vertical position to animate in a downward
3033
* direction, set the translation to start the snack bar above the target position.
3134
*/
3235
&.mat-snack-bar-top {
33-
transform: translateY(-100%);
36+
transform: translateY(-100%) translateY(#{-$mat-snack-bar-spacing-margin});
37+
38+
&.mat-snack-bar-center {
39+
transform: translateY(-100%);
40+
}
3441
}
3542

3643
@include cdk-high-contrast {

src/lib/snack-bar/snack-bar-container.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,10 @@ export const HIDE_ANIMATION = '195ms cubic-bezier(0.0,0.0,0.2,1)';
6363
},
6464
animations: [
6565
trigger('state', [
66-
// Animation from top.
67-
state('visible-top', style({transform: 'translateY(0%)'})),
68-
state('hidden-top', style({transform: 'translateY(-100%)'})),
69-
transition('visible-top => hidden-top', animate(HIDE_ANIMATION)),
70-
transition('void => visible-top', animate(SHOW_ANIMATION)),
71-
// Animation from bottom.
72-
state('visible-bottom', style({transform: 'translateY(0%)'})),
73-
state('hidden-bottom', style({transform: 'translateY(100%)'})),
74-
transition('visible-bottom => hidden-bottom', animate(HIDE_ANIMATION)),
75-
transition('void => visible-bottom',
76-
animate(SHOW_ANIMATION)),
66+
state('visible-top, visible-bottom', style({transform: 'translateY(0%)'})),
67+
transition('visible-top => hidden-top, visible-bottom => hidden-bottom',
68+
animate(HIDE_ANIMATION)),
69+
transition('void => visible-top, void => visible-bottom', animate(SHOW_ANIMATION)),
7770
])
7871
],
7972
})

0 commit comments

Comments
 (0)