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

feat(snackbar): Update styles to match guidelines #4070

Merged
merged 8 commits into from
Nov 13, 2018

Conversation

acdvorak
Copy link
Contributor

@acdvorak acdvorak commented Nov 9, 2018

Fixes #4061

This PR also deletes snackbar's JS files and unit tests to avoid spurious test failures.
They will be added back in the next PR (for issue #4062).

@codecov-io
Copy link

codecov-io commented Nov 9, 2018

Codecov Report

Merging #4070 into feat/snackbar will increase coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@                Coverage Diff                @@
##           feat/snackbar    #4070      +/-   ##
=================================================
+ Coverage          98.67%   98.74%   +0.06%     
=================================================
  Files                126      123       -3     
  Lines               5596     5406     -190     
  Branches             746      724      -22     
=================================================
- Hits                5522     5338     -184     
+ Misses                74       68       -6

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be887cb...5bd2940. Read the comment docs.

}

@mixin mdc-snackbar-min-width($min-width) {
.mdc-snackbar__surface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is regarding additional wrapper .mdc-snackbar__surface used to achieve opaque background.

Did you run into any issues using mix() sass function?

Copy link
Contributor Author

@acdvorak acdvorak Nov 10, 2018

Choose a reason for hiding this comment

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

Great question!

Two One issues:

  1. mix() prevents clients from using CSS variables
  2. If the overlay color has an alpha channel, mix() will return an rgba() value.
    This will make the snackbar's background appear semi-transparent instead of opaque, which violates the spec.

    Ok, this was a stupid argument. It probably doesn't make sense for the overlay color to have an alpha channel.

Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need CSS variable support for users using sass mixins?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If possible, yes, but if we have to choose between supporting CSS variables and having a simple Sass API, we normally go with a simple Sass API.

I'll remove the __overlay element and simplify the fill-color mixin so that it only takes 1 color parameter. The mix() function will be called in _variables.scss, similar to what mdc-chips does.

}
}

@mixin mdc-snackbar-surface-fill-color($color) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

mdc-snackbar-fill-color?

Should we expose two separate mixins? Seems like these mixins are helping customize low-level elements of this component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I definitely see your point. Having two separate mixins is not very intuitive for clients who just want to set the background-color to a specific hex value.

However, the internal guidelines say that the rendered background-color of a snackbar should be a combination of two theme colors: surface and overlay. It may be low-level, but it's how the theming system works. I'm not sure what the alternative is.

Would it be better to have a single mixin that accepts two color params? E.g.:

@mixin mdc-snackbar-fill-color(
  $surface-color: surface,
  $overlay-color: on-surface,
  $overlay-opacity: high
) {
  .mdc-snackbar__surface {
    @include mdc-theme-prop(background-color, $surface-color);
  }

  .mdc-snackbar__overlay {
    $overlay-opacity-value: if(
      type-of($overlay-opacity) == number,
      $overlay-opacity,
      mdc-theme-text-emphasis($overlay-opacity)
    );
    $overlay-color-value: rgba(
      mdc-theme-prop-value($overlay-color),
      $overlay-opacity-value
    );

    @include mdc-theme-prop(background-color, $overlay-color-value);
  }
}

If we decide to stick with two separate mixins, I probably wouldn't want to rename them, because IMO it would be confusing to have:

  • mdc-snackbar-fill-color (targets __surface)
  • mdc-snackbar-overlay-color (targets __overlay)

The name mdc-snackbar-fill-color would be misleading, because it doesn't actually set the rendered fill color of the component—just the background behind the overlay.

WDYT? Is there an alternative I'm not seeing here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be agreeable to one mixin w/ arguments for both colors. Separate mixins seems prone to people accidentally overlooking one or the other and not realizing they influence each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -1077,6 +1077,123 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/10/23/19_08_56_617/spec/mdc-select/mixins/shape-radius.html.windows_ie_11.png"
}
},
"spec/mdc-snackbar/classes/baseline-with-action.html": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Snackbar is being clipped in iPhone 5 viewport.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, good catch! 👍

That's due to the default min-width value of 344px from the spec:

https://material.io/design/components/snackbars.html#spec

image

I'll follow up with Design on this.

(OOC, why did you think to test it on an iPhone 5? Never would have occurred to me 😝)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was testing if snackbar snaps to screen edges for smaller browsers 🙂


.mdc-snackbar--stacked & {
flex-direction: column;
align-items: flex-start;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this flip for RTL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! That's the beauty of flexbox and flex-start: It's already RTL-aware! 🎉

BTW, you can add ?dir=rtl to any screenshot test page URL to see what it looks like in RTL:

https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/11/09/02_51_51_193/spec/mdc-snackbar/index.html?dir=rtl

LTR:

image

RTL:

image

}

@mixin mdc-snackbar-shape-radius($radius) {
// The mdc-snackbar__overlay selector is needed to prevent the overlay's
Copy link
Contributor

Choose a reason for hiding this comment

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

You say the snackbar__overlay selector is needed... but it's not there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, removed

}
}

@mixin mdc-snackbar-surface-fill-color($color) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be agreeable to one mixin w/ arguments for both colors. Separate mixins seems prone to people accidentally overlooking one or the other and not realizing they influence each other.

// Private
//

$mdc-snackbar-enter-delay_: 0ms;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason these are distinguished as private, given the request we've gotten to expose everything as overrideable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call—made them "public"

@@ -1,5 +1,5 @@
//
// Copyright 2017 Google Inc.
// Copyright 2018 Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

We typically don't change the copyright year in pre-existing files. I can buy the argument in other cases that the files are effectively being replaced, but this one especially seems somewhat intact.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually rewrote this file from scratch, so I figured that needed a year bump

@@ -16,7 +16,12 @@
"dependencies": {
"@material/animation": "^0.41.0",
"@material/base": "^0.41.0",
"@material/button": "^0.41.0",
"@material/icon-button": "^0.41.0",
"@material/dom": "^0.41.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I take it you're expecting to use this in the JS portion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I just forgot to remove it from this PR. Fixed!

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

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

Looks good overall! Added few comments mostly nit.

Are you planning to update README file in your next PR?

}

@mixin mdc-snackbar-min-width($min-width) {
.mdc-snackbar__surface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need CSS variable support for users using sass mixins?

}

@mixin mdc-snackbar-fill-color($overlay-color, $overlay-opacity, $surface-color: surface) {
.mdc-snackbar__surface {
Copy link
Collaborator

Choose a reason for hiding this comment

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

surface is a global override and can be customized using sass variable - $mdc-theme-surface. User may not need to send surface color here again?

I'm assuming the overlay color should blend with the global surface color which might be rendered behind snackbar from other components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Individual components can technically have their own independent "surface" color, which may or may not be the same as the global surface color.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked with designer today, Snackbar doesn't seem to allow customization for snackbar container (surface).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Internal customers need a different background color, so we still need to at least provide a mixin to change it. But I'll remove the __overlay element and simplify the fill-color mixin so that it only takes 1 parameter.

@@ -1077,6 +1077,123 @@
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/10/23/19_08_56_617/spec/mdc-select/mixins/shape-radius.html.windows_ie_11.png"
}
},
"spec/mdc-snackbar/classes/baseline-with-action.html": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was testing if snackbar snaps to screen edges for smaller browsers 🙂

justify-content: flex-start;
margin-top: -12px;
margin-bottom: 8px;
display: none;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need to set this to display: none when the root has aria-hidden="true"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, display: none is necessary to prevent the elements from being focusable when the user presses the Tab key.

<html lang="en">
<head>
<meta charset="utf-8">
<title>Baseline Snackbar with Action - MDC Web Screenshot Test</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

Update title?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@import "../packages/mdc-textfield/mdc-text-field";
@import "../../../../packages/mdc-snackbar/mixins";
@import "../../../../packages/mdc-theme/color-palette";
@import "../mixins";
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't seem to be using this here. Should we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@import "@material/rtl/mixins";
@import "@material/theme/functions";
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all of these theme imports used? I don't see mdc-theme anywhere in this file. I think they're used in _mixins instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

// > To disable tap highlighting, set the alpha value to 0 (invisible).
// > If you set the alpha value to 1.0 (opaque), the element is not visible when tapped.
// See https://github.com/ben-eb/postcss-colormin/issues/1
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed on the entire snackbar element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, iOS Safari displays a tap highlight on the entire snackbar element 🤷‍♀️

display: flex;

// Non-static positioning is required to make `overflow: hidden` work in Safari.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we really running into this bug? Wouldn't we want relative positioning anyway because the overlay element is absolutely-positioned inside the surface element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I've removed the __overlay element and simplified the fill-color mixin to only take 1 parameter, we don't need this anymore. Removed!

pointer-events: auto; // Allow mouse events on surface element while snackbar is open
}

.mdc-snackbar--closing & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why there's a --closing but no --opening? It's probably hard to surmise without having the JS APIs to actually cause animation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Opening and closing use different animations, so I need a separate class for --closing.
The opening animation is defined in --open.

margin: 0;
// Two selectors are needed to increase specificity above `.material-icons`.
// stylelint-disable-next-line selector-class-pattern
.mdc-snackbar__action-icon.material-icons {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this really be using material-icons in the selector? What would happen if someone used an image or svg? Should we do the same-class-twice trick instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same-class-twice trick it is!

Copy link
Collaborator

@abhiomkar abhiomkar left a comment

Choose a reason for hiding this comment

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

LGTM. Please address Ken's comments.

@acdvorak acdvorak merged commit fa2bc17 into feat/snackbar Nov 13, 2018
@acdvorak acdvorak deleted the feat/snackbar--styles branch November 13, 2018 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants