Skip to content

fix(material/snack-bar): incorrect width at some breakpoints #26334

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

Merged
merged 1 commit into from
Jan 5, 2023
Merged
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
30 changes: 20 additions & 10 deletions src/material/snack-bar/snack-bar-container.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use 'sass:map';
@use '@angular/cdk';
@use '@material/snackbar/snackbar' as mdc-snackbar;
@use '@material/snackbar/snackbar-theme' as mdc-snackbar-theme;
@use '../core/mdc-helpers/mdc-helpers';
Expand All @@ -10,13 +9,28 @@
@include mdc-snackbar.static-styles($query: mdc-helpers.$mdc-base-styles-without-animation-query);
}

@mixin _container-min-width {
$min-width: mdc-snackbar-theme.$min-width;
$mobile-breakpoint: mdc-snackbar-theme.$mobile-breakpoint;

// The styles weren't included in `static-styles` so we need to add them ourselves.
@include mdc-snackbar-theme.min-width(
$min-width: $min-width,
$mobile-breakpoint: $mobile-breakpoint,
$query: mdc-helpers.$mdc-base-styles-query
);

// The MDC `min-width` mixin has a similar breakpoint that sets `min-width: 100%` on the surface
// element to make it span the entire viewport, however it ends up collapsing because the
// container is `width: auto`. This query ensures that the surface will span the whole viewport.
Comment on lines +24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we open an issue OR code change with MDC for this? It seems like 100vw more closely matches the intent of their style

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDC would've been 100vw as well, but we override their position: fixed positioning in order to fit the snack bar in our overlay positioning model.

@media (max-width: $mobile-breakpoint), (max-width: $min-width) {
width: 100vw;
}
}

.mat-mdc-snack-bar-container {
@include mdc-helpers.disable-mdc-fallback-declarations {
// The styles weren't included in `static-styles` so we need to add them ourselves.
@include mdc-snackbar-theme.min-width(
mdc-snackbar-theme.$min-width,
$query: mdc-helpers.$mdc-base-styles-query
);
@include _container-min-width;
@include mdc-snackbar-theme.max-width(
mdc-snackbar-theme.$max-width,
$query: mdc-helpers.$mdc-base-styles-query
Expand Down Expand Up @@ -60,10 +74,6 @@
// of positions, so we'll defer logic there.
position: static;

@include cdk.high-contrast(active, off) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change. I just noticed that we don't need it anymore.

border: solid 1px;
}

// The `mat-mdc-button` and `:not(:disabled)` here are redundant, but we need them to increase
// the specificity over the button styles that may bleed in from the rest of the app.
.mat-mdc-button.mat-mdc-snack-bar-action:not(:disabled) {
Expand Down