Skip to content

Commit 30e9205

Browse files
authored
fix(material-experimental/mdc-button): high contrast outline for solitary (#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).
1 parent 492268a commit 30e9205

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

src/material-experimental/mdc-button/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ng_module(
2020
],
2121
),
2222
assets = [
23+
":button_high_contrast_scss",
2324
":button_scss",
2425
":fab_scss",
2526
":icon-button_scss",
@@ -53,12 +54,18 @@ sass_binary(
5354
],
5455
deps = [
5556
":button_base_scss_lib",
56-
"//src/cdk/a11y:a11y_scss_lib",
5757
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
5858
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
5959
],
6060
)
6161

62+
sass_binary(
63+
name = "button_high_contrast_scss",
64+
src = "button-high-contrast.scss",
65+
include_paths = ["external/npm/node_modules"],
66+
deps = ["//src/cdk/a11y:a11y_scss_lib"],
67+
)
68+
6269
sass_binary(
6370
name = "fab_scss",
6471
src = "fab.scss",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@use '../../cdk/a11y';
2+
3+
// Add an outline to make buttons more visible in high contrast mode. Stroked buttons and FABs
4+
// don't need a special look in high-contrast mode, because those already have an outline.
5+
.mat-mdc-button:not(.mdc-button--outlined),
6+
.mat-mdc-unelevated-button:not(.mdc-button--outlined),
7+
.mat-mdc-raised-button:not(.mdc-button--outlined),
8+
.mat-mdc-outlined-button:not(.mdc-button--outlined),
9+
.mat-mdc-icon-button {
10+
@include a11y.high-contrast(active, off) {
11+
outline: solid 1px;
12+
}
13+
}
14+
15+
@include a11y.high-contrast(active, off) {
16+
.mat-mdc-button-base:focus {
17+
outline: solid 3px;
18+
}
19+
}

src/material-experimental/mdc-button/button.scss

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@use '@material/button/variables' as mdc-button-variables;
33
@use '../../material/core/style/private';
44
@use '../mdc-helpers/mdc-helpers';
5-
@use '../../cdk/a11y';
65
@use 'button-base';
76

87

@@ -42,24 +41,6 @@
4241
}
4342
}
4443

45-
// Add an outline to make buttons more visible in high contrast mode. Stroked buttons and FABs
46-
// don't need a special look in high-contrast mode, because those already have an outline.
47-
.mat-mdc-button:not(.mdc-button--outlined),
48-
.mat-mdc-unelevated-button:not(.mdc-button--outlined),
49-
.mat-mdc-raised-button:not(.mdc-button--outlined),
50-
.mat-mdc-outlined-button:not(.mdc-button--outlined),
51-
.mat-mdc-icon-button {
52-
@include a11y.high-contrast(active, off) {
53-
outline: solid 1px;
54-
}
55-
}
56-
57-
@include a11y.high-contrast(active, off) {
58-
.mat-mdc-button-base:focus {
59-
outline: solid 3px;
60-
}
61-
}
62-
6344
// Since the stroked button has has an actual border that reduces the available space for
6445
// child elements such as the ripple container or focus overlay, an inherited border radius
6546
// for the absolute-positioned child elements does not work properly. This is because the

src/material-experimental/mdc-button/button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
button[mat-stroked-button]
4343
`,
4444
templateUrl: 'button.html',
45-
styleUrls: ['button.css'],
45+
styleUrls: ['button.css', 'button-high-contrast.css'],
4646
inputs: MAT_BUTTON_INPUTS,
4747
host: MAT_BUTTON_HOST,
4848
exportAs: 'matButton',
@@ -73,7 +73,7 @@ export class MatButton extends MatButtonBase {
7373
host: MAT_ANCHOR_HOST,
7474
inputs: MAT_ANCHOR_INPUTS,
7575
templateUrl: 'button.html',
76-
styleUrls: ['button.css'],
76+
styleUrls: ['button.css', 'button-high-contrast.css'],
7777
encapsulation: ViewEncapsulation.None,
7878
changeDetection: ChangeDetectionStrategy.OnPush,
7979
})

src/material-experimental/mdc-button/icon-button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
@Component({
3636
selector: `button[mat-icon-button]`,
3737
templateUrl: 'button.html',
38-
styleUrls: ['icon-button.css'],
38+
styleUrls: ['icon-button.css', 'button-high-contrast.css'],
3939
inputs: MAT_BUTTON_INPUTS,
4040
host: MAT_BUTTON_HOST,
4141
exportAs: 'matButton',
@@ -61,7 +61,7 @@ export class MatIconButton extends MatButtonBase {
6161
@Component({
6262
selector: `a[mat-icon-button]`,
6363
templateUrl: 'button.html',
64-
styleUrls: ['icon-button.css'],
64+
styleUrls: ['icon-button.css', 'button-high-contrast.css'],
6565
inputs: MAT_ANCHOR_INPUTS,
6666
host: MAT_ANCHOR_HOST,
6767
exportAs: 'matButton, matAnchor',

0 commit comments

Comments
 (0)