Skip to content

Commit 06cbe30

Browse files
committed
feat(material-experimental/button): anchor disabled state
1 parent f5e087b commit 06cbe30

File tree

7 files changed

+87
-11
lines changed

7 files changed

+87
-11
lines changed

src/dev-app/mdc-button/mdc-button-demo.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ <h4 class="demo-section-header">Buttons</h4>
1212
<mat-icon>check</mat-icon>
1313
</button>
1414
</section>
15+
<section>
16+
<button mat-button disabled>normal</button>
17+
<button mat-raised-button disabled>raised</button>
18+
<button mat-stroked-button disabled>stroked</button>
19+
<button mat-flat-button disabled>flat</button>
20+
<button mat-fab disabled>
21+
<mat-icon>check</mat-icon>
22+
</button>
23+
<button mat-mini-fab disabled>
24+
<mat-icon>check</mat-icon>
25+
</button>
26+
</section>
1527

1628
<h4 class="demo-section-header">Anchors</h4>
1729
<section>
@@ -26,6 +38,18 @@ <h4 class="demo-section-header">Anchors</h4>
2638
<mat-icon>check</mat-icon>
2739
</a>
2840
</section>
41+
<section>
42+
<a href="//www.google.com" disabled mat-button color="primary">SEARCH</a>
43+
<a href="//www.google.com" disabled mat-raised-button>SEARCH</a>
44+
<a href="//www.google.com" disabled mat-stroked-button color="primary">SEARCH</a>
45+
<a href="//www.google.com" disabled mat-flat-button>SEARCH</a>
46+
<a href="//www.google.com" disabled mat-fab>
47+
<mat-icon>check</mat-icon>
48+
</a>
49+
<a href="//www.google.com" disabled mat-mini-fab>
50+
<mat-icon>check</mat-icon>
51+
</a>
52+
</section>
2953

3054
<h4 class="demo-section-header">Text Buttons [mat-button]</h4>
3155
<section>

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@
1313
@content;
1414
}
1515
}
16+
17+
// MDC's disabled buttons define a default cursor with pointer-events none. However, they select
18+
// :disabled for this, which does not affect anchor tags.
19+
@mixin _mat-button-disabled() {
20+
&[disabled] {
21+
cursor: default;
22+
pointer-events: none;
23+
}
24+
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
@import '@material/button/mixins';
2+
@import '@material/button/variables';
23
@import '@material/fab/mixins';
34
@import '@material/ripple/mixins';
45
@import '@material/icon-button/mixins';
56
@import '../mdc-helpers/mdc-helpers';
67

8+
// Applies the disabled theme color to the text color.
9+
@mixin _mat-button-disabled-color() {
10+
@include mdc-theme-prop(color,
11+
mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
12+
}
13+
14+
// Applies the disabled theme background color for raised buttons. Value is taken from
15+
// mixin `mdc-button--filled`
16+
@mixin _mat-button-disabled-background() {
17+
@include mdc-theme-prop(background-color, rgba(mdc-theme-prop-value(on-surface), 0.12));
18+
}
19+
20+
721
@mixin mat-button-theme-mdc($theme) {
822
@include mat-using-mdc-theme($theme) {
923
// Add state interactions for hover, focus, press, active. Colors are changed based on
@@ -39,6 +53,10 @@
3953
@include mdc-button-ink-color(on-error, $query: $mat-theme-styles-query);
4054
@include mdc-states-base-color(on-error, $query: $mat-theme-styles-query);
4155
}
56+
57+
&[disabled][disabled] {
58+
@include _mat-button-disabled-background();
59+
}
4260
}
4361

4462
.mat-mdc-outlined-button {
@@ -49,6 +67,26 @@
4967
&.mat-warn {
5068
@include mdc-button-outline-color(error, $query: $mat-theme-styles-query);
5169
}
70+
71+
&[disabled][disabled] {
72+
@include mdc-theme-prop(border-color,
73+
mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
74+
}
75+
}
76+
77+
.mat-mdc-raised-button {
78+
&[disabled][disabled] {
79+
@include mdc-elevation(0, $query: $mat-theme-styles-query);
80+
}
81+
}
82+
83+
// MDC adds theme color by using :not(:disabled), so just using [disabled] once will not
84+
// override this and also will not apply to anchor tags. This needs to override the
85+
// previously set theme color, so it must be ordered after the theme styles.
86+
.mat-mdc-button, .mat-mdc-raised-button, .mat-mdc-unelevated-button, .mat-mdc-outlined-button {
87+
&[disabled][disabled] {
88+
@include _mat-button-disabled-color();
89+
}
5290
}
5391

5492
@include mdc-button-without-ripple($query: $mat-theme-styles-query);
@@ -78,6 +116,12 @@
78116
@include mdc-fab-container-color(error, $query: $mat-theme-styles-query);
79117
@include mdc-fab-ink-color(on-error, $query: $mat-theme-styles-query);
80118
}
119+
120+
&[disabled][disabled] {
121+
@include _mat-button-disabled-color();
122+
@include _mat-button-disabled-background();
123+
@include mdc-elevation(0, $query: $mat-theme-styles-query);
124+
}
81125
}
82126

83127
@include mdc-fab-without-ripple($query: $mat-theme-styles-query);
@@ -106,6 +150,10 @@
106150
@include mdc-states-base-color(error, $query: $mat-theme-styles-query);
107151
@include mdc-icon-button-ink-color(error, $query: $mat-theme-styles-query);
108152
}
153+
154+
&[disabled][disabled] {
155+
@include _mat-button-disabled-color();
156+
}
109157
}
110158

111159
@include mdc-icon-button-without-ripple($query: $mat-theme-styles-query);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ export const MAT_ANCHOR_INPUTS = ['disabled', 'disableRipple', 'color', 'tabInde
118118

119119
/** Shared host configuration for buttons using the `<a>` tag. */
120120
export const MAT_ANCHOR_HOST = {
121-
...MAT_BUTTON_HOST,
121+
'[attr.disabled]': 'disabled || null',
122+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
123+
122124
// Note that we ignore the user-specified tabindex when it's disabled for
123125
// consistency with the `mat-button` applied on native buttons where even
124126
// though they have an index, they're not tabbable.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
}
1717

1818
@include _mat-button-interactive();
19+
@include _mat-button-disabled();
1920
}
20-

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88

99
.mat-mdc-fab, .mat-mdc-mini-fab {
1010
@include _mat-button-interactive();
11-
12-
// Spec does not define disabled FAB buttons but Angular Material does support it.
13-
&:disabled {
14-
background-color: rgba(mdc-theme-prop-value(on-surface), 0.12);
15-
color: $mdc-button-disabled-ink-color;
16-
cursor: default;
17-
pointer-events: none;
18-
box-shadow: none;
19-
}
11+
@include _mat-button-disabled();
2012
}
2113

2214
.mat-mdc-fab, .mat-mdc-mini-fab {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
// Border radius is inherited by ripple to know its shape. Set to 50% so the ripple is round.
1313
border-radius: 50%;
1414

15+
@include _mat-button-disabled();
1516
}

0 commit comments

Comments
 (0)