Skip to content

Commit

Permalink
fix(material-experimental/mdc-button): high contrast outline for soli…
Browse files Browse the repository at this point in the history
…tary (#22987)

icon-buttons

The high-contrast style for all buttons was previously defined in
`button.scss`, but icon-buttons load `icon-button.scss`. This means that
the high contrast style for icon buttons was only loaded when another
type of button was on the page. This change moves the high-contrast styles to their own file that's referenced from buttons and icon-buttons (but not FABs).

(cherry picked from commit 30e9205)
  • Loading branch information
jelbourn authored and mmalerba committed Jul 23, 2021
1 parent e5d685a commit 762140a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
9 changes: 8 additions & 1 deletion src/material-experimental/mdc-button/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ng_module(
],
),
assets = [
":button_high_contrast_scss",
":button_scss",
":fab_scss",
":icon-button_scss",
Expand Down Expand Up @@ -53,12 +54,18 @@ sass_binary(
],
deps = [
":button_base_scss_lib",
"//src/cdk/a11y:a11y_scss_lib",
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
],
)

sass_binary(
name = "button_high_contrast_scss",
src = "button-high-contrast.scss",
include_paths = ["external/npm/node_modules"],
deps = ["//src/cdk/a11y:a11y_scss_lib"],
)

sass_binary(
name = "fab_scss",
src = "fab.scss",
Expand Down
19 changes: 19 additions & 0 deletions src/material-experimental/mdc-button/button-high-contrast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@use '../../cdk/a11y';

// Add an outline to make buttons more visible in high contrast mode. Stroked buttons and FABs
// don't need a special look in high-contrast mode, because those already have an outline.
.mat-mdc-button:not(.mdc-button--outlined),
.mat-mdc-unelevated-button:not(.mdc-button--outlined),
.mat-mdc-raised-button:not(.mdc-button--outlined),
.mat-mdc-outlined-button:not(.mdc-button--outlined),
.mat-mdc-icon-button {
@include a11y.high-contrast(active, off) {
outline: solid 1px;
}
}

@include a11y.high-contrast(active, off) {
.mat-mdc-button-base:focus {
outline: solid 3px;
}
}
19 changes: 0 additions & 19 deletions src/material-experimental/mdc-button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
@use '@material/button/variables' as mdc-button-variables;
@use '../../material/core/style/private';
@use '../mdc-helpers/mdc-helpers';
@use '../../cdk/a11y';
@use 'button-base';


Expand Down Expand Up @@ -42,24 +41,6 @@
}
}

// Add an outline to make buttons more visible in high contrast mode. Stroked buttons and FABs
// don't need a special look in high-contrast mode, because those already have an outline.
.mat-mdc-button:not(.mdc-button--outlined),
.mat-mdc-unelevated-button:not(.mdc-button--outlined),
.mat-mdc-raised-button:not(.mdc-button--outlined),
.mat-mdc-outlined-button:not(.mdc-button--outlined),
.mat-mdc-icon-button {
@include a11y.high-contrast(active, off) {
outline: solid 1px;
}
}

@include a11y.high-contrast(active, off) {
.mat-mdc-button-base:focus {
outline: solid 3px;
}
}

// Since the stroked button has has an actual border that reduces the available space for
// child elements such as the ripple container or focus overlay, an inherited border radius
// for the absolute-positioned child elements does not work properly. This is because the
Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
button[mat-stroked-button]
`,
templateUrl: 'button.html',
styleUrls: ['button.css'],
styleUrls: ['button.css', 'button-high-contrast.css'],
inputs: MAT_BUTTON_INPUTS,
host: MAT_BUTTON_HOST,
exportAs: 'matButton',
Expand Down Expand Up @@ -73,7 +73,7 @@ export class MatButton extends MatButtonBase {
host: MAT_ANCHOR_HOST,
inputs: MAT_ANCHOR_INPUTS,
templateUrl: 'button.html',
styleUrls: ['button.css'],
styleUrls: ['button.css', 'button-high-contrast.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
Expand Down
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-button/icon-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
@Component({
selector: `button[mat-icon-button]`,
templateUrl: 'button.html',
styleUrls: ['icon-button.css'],
styleUrls: ['icon-button.css', 'button-high-contrast.css'],
inputs: MAT_BUTTON_INPUTS,
host: MAT_BUTTON_HOST,
exportAs: 'matButton',
Expand All @@ -61,7 +61,7 @@ export class MatIconButton extends MatButtonBase {
@Component({
selector: `a[mat-icon-button]`,
templateUrl: 'button.html',
styleUrls: ['icon-button.css'],
styleUrls: ['icon-button.css', 'button-high-contrast.css'],
inputs: MAT_ANCHOR_INPUTS,
host: MAT_ANCHOR_HOST,
exportAs: 'matButton, matAnchor',
Expand Down

0 comments on commit 762140a

Please sign in to comment.