Skip to content

Commit

Permalink
change all buttons to use the same focus styling technique
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed May 31, 2016
1 parent 745ba15 commit d9dcf74
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
19 changes: 5 additions & 14 deletions src/components/button/_button-base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ $md-mini-fab-padding: 8px !default;
&[disabled] {
cursor: default;
}

&.md-button-focus {
@include md-button-focus();
}
}

// Applies styles to buttons with backgrounds: raised, fab, and mini-fab
Expand All @@ -85,20 +89,7 @@ $md-mini-fab-padding: 8px !default;
@include md-elevation(8);
}

&.md-button-focus:after {
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
// black, 12% opacity shade over the normal color (for both light and dark themes).
// We do this by placing an :after psuedo-element with the appropriate shade over the button.
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
content: '';
background-color: rgba(black, 0.12);
border-radius: inherit;
pointer-events: none;
}
// from here

&[disabled] {
box-shadow: none;
Expand Down
35 changes: 32 additions & 3 deletions src/components/button/_button-theme.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

// Applies specified coloring to three supported palettes
@mixin md-button-theme ($property, $color: 'default', $opacity: 1) {
/** Applies a property to an md-button element for each of the supported palettes. */
@mixin md-button-theme($property, $color: 'default', $opacity: 1) {
&.md-primary {
#{$property}: md-color($md-primary, $color, $opacity);
}
Expand All @@ -18,3 +17,33 @@
}
}
}

/** Applies a focus style to an md-button element for each of the supported palettes. */
@mixin md-button-focus {
&::after {
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
// black, 12% opacity shade over the normal color (for both light and dark themes).
// We do this by placing an :after psuedo-element with the appropriate shade over the button.
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
content: '';
background-color: rgba(black, 0.12);
border-radius: inherit;
pointer-events: none;
}

&.md-primary::after {
background-color: md-color($md-primary, 0.12);
}

&.md-accent::after {
background-color: md-color($md-accent, 0.12);
}

&.md-warn::after {
background-color: md-color($md-warn, 0.12);
}
}
18 changes: 7 additions & 11 deletions src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
[md-button] {
@extend %md-button-base;

&:hover, &.md-button-focus {
background-color: md-color($md-foreground, base, 0.12);
@include md-button-theme('background-color', 0.12);
}

&[disabled]:hover {
&.md-primary, &.md-accent, &.md-warn, &:hover {
background-color: transparent;
Expand Down Expand Up @@ -43,19 +38,20 @@
line-height: $md-icon-button-line-height;
border-radius: $md-icon-button-border-radius;

&.md-button-focus {
background-color: md-color($md-foreground, base, 0.12);
@include md-button-theme('background-color', 0.12);
}

.md-button-wrapper > * {
vertical-align: middle;
}
}

// Only flat buttons and icon buttons (not raised or fabs) have a hover style.
[md-button]:hover, [md-icon-button]:hover {
// Use the same visual treatment for hover as for focus.
@include md-button-focus();
}

// Applies a clearer border for high-contrast mode (a11y)
@media screen and (-ms-high-contrast: active) {
.md-raised-button, .md-fab, .md-mini-fab {
border: 1px solid #fff;
}
}
}

0 comments on commit d9dcf74

Please sign in to comment.