Skip to content

Commit dd4a606

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

File tree

7 files changed

+73
-11
lines changed

7 files changed

+73
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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';
@@ -39,6 +40,10 @@
3940
@include mdc-button-ink-color(on-error, $query: $mat-theme-styles-query);
4041
@include mdc-states-base-color(on-error, $query: $mat-theme-styles-query);
4142
}
43+
44+
&[disabled][disabled] {
45+
@include mdc-theme-prop(background-color, rgba(mdc-theme-prop-value(on-surface), .12));
46+
}
4247
}
4348

4449
.mat-mdc-outlined-button {
@@ -49,6 +54,25 @@
4954
&.mat-warn {
5055
@include mdc-button-outline-color(error, $query: $mat-theme-styles-query);
5156
}
57+
58+
&[disabled][disabled] {
59+
@include mdc-theme-prop(border-color, mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
60+
}
61+
}
62+
63+
// MDC adds theme color by using :not(:disabled), so just using [disabled] once will not
64+
// override this and also will not apply to anchor tags. This needs to override the
65+
// previously set theme color, so it must be ordered after the theme styles.
66+
.mat-mdc-button, .mat-mdc-raised-button, .mat-mdc-unelevated-button, .mat-mdc-outlined-button {
67+
&[disabled][disabled] {
68+
@include mdc-theme-prop(color, mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
69+
}
70+
}
71+
72+
.mat-mdc-raised-button {
73+
&[disabled][disabled] {
74+
@include mdc-elevation(0, $query: $mat-theme-styles-query);
75+
}
5276
}
5377

5478
@include mdc-button-without-ripple($query: $mat-theme-styles-query);
@@ -78,6 +102,12 @@
78102
@include mdc-fab-container-color(error, $query: $mat-theme-styles-query);
79103
@include mdc-fab-ink-color(on-error, $query: $mat-theme-styles-query);
80104
}
105+
106+
&[disabled][disabled] {
107+
@include mdc-theme-prop(color, mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
108+
@include mdc-theme-prop(background-color, rgba(mdc-theme-prop-value(on-surface), .12));
109+
@include mdc-elevation(0, $query: $mat-theme-styles-query);
110+
}
81111
}
82112

83113
@include mdc-fab-without-ripple($query: $mat-theme-styles-query);
@@ -106,6 +136,10 @@
106136
@include mdc-states-base-color(error, $query: $mat-theme-styles-query);
107137
@include mdc-icon-button-ink-color(error, $query: $mat-theme-styles-query);
108138
}
139+
140+
&[disabled][disabled] {
141+
@include mdc-theme-prop(color, mdc-theme-ink-color-for-fill_(disabled, $mdc-theme-background));
142+
}
109143
}
110144

111145
@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)