Skip to content

Commit 66b17b7

Browse files
committed
fix(material-experimental/mdc-button): high contrast outline for solitary
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 4caf039 commit 66b17b7

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-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",
@@ -54,12 +55,18 @@ sass_binary(
5455
],
5556
deps = [
5657
":button_base_scss_lib",
57-
"//src/cdk/a11y:a11y_scss_lib",
5858
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
5959
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
6060
],
6161
)
6262

63+
sass_binary(
64+
name = "button_high_contrast_scss",
65+
src = "button-high-contrast.scss",
66+
include_paths = ["external/npm/node_modules"],
67+
deps = ["//src/cdk/a11y:a11y_scss_lib"],
68+
)
69+
6370
sass_binary(
6471
name = "fab_scss",
6572
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
@@ -1,7 +1,6 @@
11
@use '@material/button/button' as mdc-button;
22
@use '@material/button/variables' as mdc-button-variables;
33
@use '../mdc-helpers/mdc-helpers';
4-
@use '../../cdk/a11y';
54
@use 'button-base';
65

76

@@ -40,24 +39,6 @@
4039
}
4140
}
4241

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@use '@material/icon-button' as mdc-icon-button;
22
@use '../mdc-helpers/mdc-helpers';
33
@use 'button-base';
4+
@use '../../cdk/a11y';
45

56
@include mdc-icon-button.without-ripple($query: mdc-helpers.$mat-base-styles-query);
67

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)