Skip to content

Commit ac78c74

Browse files
committed
fix(material-experimental/mdc-button): split up fab and mini fab
1 parent 71031ca commit ac78c74

File tree

2 files changed

+98
-11
lines changed

2 files changed

+98
-11
lines changed

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

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,33 @@ import {
2727
MatButtonBase
2828
} from './button-base';
2929
import {ThemePalette} from '@angular/material-experimental/mdc-core';
30+
import {coerceBooleanProperty} from '@angular/cdk/coercion';
3031

3132
/**
3233
* Material Design floating action button (FAB) component. These buttons represent the primary
3334
* or most common action for users to interact with.
3435
* See https://material.io/components/buttons-floating-action-button/
3536
*
36-
* The `MatFabButton` class has two appearances: normal and mini.
37+
* The `MatFabButton` class has two appearances: normal and extended.
3738
*/
3839
@Component({
39-
selector: `button[mat-fab], button[mat-mini-fab]`,
40+
selector: `button[mat-fab]`,
4041
templateUrl: 'button.html',
4142
styleUrls: ['fab.css'],
42-
inputs: [...MAT_BUTTON_INPUTS, 'extended'],
43+
// TODO: change to MAT_BUTTON_INPUTS/MAT_BUTTON_HOST with spread after ViewEngine is deprecated
44+
inputs: ['disabled', 'disableRipple', 'color', 'extended'],
4345
host: {
4446
'[class.mdc-fab--extended]': 'extended',
45-
'[class.mat-mdc-extended-fab]': 'extended', ...MAT_BUTTON_HOST
47+
'[class.mat-mdc-extended-fab]': 'extended',
48+
'[attr.disabled]': 'disabled || null',
49+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
50+
// MDC automatically applies the primary theme color to the button, but we want to support
51+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
52+
// select and style this "theme".
53+
'[class.mat-unthemed]': '!color',
54+
// Add a class that applies to all buttons. This makes it easier to target if somebody
55+
// wants to target all Material buttons.
56+
'[class.mat-mdc-button-base]': 'true',
4657
},
4758
exportAs: 'matButton',
4859
encapsulation: ViewEncapsulation.None,
@@ -52,7 +63,9 @@ export class MatFabButton extends MatButtonBase {
5263
// The FAB by default has its color set to accent.
5364
color = 'accent' as ThemePalette;
5465

55-
extended: boolean;
66+
private _extended: boolean;
67+
get extended() { return this._extended; }
68+
set extended(extended: any) { this._extended = coerceBooleanProperty(extended); }
5669

5770
constructor(
5871
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
@@ -61,22 +74,64 @@ export class MatFabButton extends MatButtonBase {
6174
}
6275
}
6376

77+
/**
78+
* Material Design mini floating action button (FAB) component. These buttons represent the primary
79+
* or most common action for users to interact with.
80+
* See https://material.io/components/buttons-floating-action-button/
81+
*/
82+
@Component({
83+
selector: `button[mat-mini-fab]`,
84+
templateUrl: 'button.html',
85+
styleUrls: ['fab.css'],
86+
inputs: MAT_BUTTON_INPUTS,
87+
host: MAT_BUTTON_HOST,
88+
exportAs: 'matButton',
89+
encapsulation: ViewEncapsulation.None,
90+
changeDetection: ChangeDetectionStrategy.OnPush,
91+
})
92+
export class MatMiniFabButton extends MatButtonBase {
93+
// The FAB by default has its color set to accent.
94+
color = 'accent' as ThemePalette;
95+
96+
constructor(
97+
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
98+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
99+
super(elementRef, platform, ngZone, animationMode);
100+
}
101+
}
102+
64103

65104
/**
66105
* Material Design floating action button (FAB) component for anchor elements. Anchor elements
67106
* are used to provide links for the user to navigate across different routes or pages.
68107
* See https://material.io/components/buttons-floating-action-button/
69108
*
70-
* The `MatFabAnchor` class has two appearances: normal and mini.
109+
* The `MatFabAnchor` class has two appearances: normal and extended.
71110
*/
72111
@Component({
73-
selector: `a[mat-fab], a[mat-mini-fab]`,
112+
selector: `a[mat-fab]`,
74113
templateUrl: 'button.html',
75114
styleUrls: ['fab.css'],
76-
inputs: [...MAT_ANCHOR_INPUTS, 'extended'],
115+
// TODO: change to MAT_ANCHOR_INPUTS/MAT_ANCHOR_HOST with spread after ViewEngine is deprecated
116+
inputs: ['disabled', 'disableRipple', 'color', 'tabIndex', 'extended'],
77117
host: {
78118
'[class.mdc-fab--extended]': 'extended',
79-
'[class.mat-mdc-extended-fab]': 'extended', ...MAT_ANCHOR_HOST
119+
'[class.mat-mdc-extended-fab]': 'extended',
120+
'[attr.disabled]': 'disabled || null',
121+
'[class._mat-animation-noopable]': '_animationMode === "NoopAnimations"',
122+
123+
// Note that we ignore the user-specified tabindex when it's disabled for
124+
// consistency with the `mat-button` applied on native buttons where even
125+
// though they have an index, they're not tabbable.
126+
'[attr.tabindex]': 'disabled ? -1 : (tabIndex || 0)',
127+
'[attr.aria-disabled]': 'disabled.toString()',
128+
// MDC automatically applies the primary theme color to the button, but we want to support
129+
// an unthemed version. If color is undefined, apply a CSS class that makes it easy to
130+
// select and style this "theme".
131+
'[class.mat-unthemed]': '!color',
132+
// Add a class that applies to all buttons. This makes it easier to target if somebody
133+
// wants to target all Material buttons.
134+
'[class.mat-mdc-button-base]': 'true',
80135
},
81136
exportAs: 'matButton, matAnchor',
82137
encapsulation: ViewEncapsulation.None,
@@ -86,11 +141,39 @@ export class MatFabAnchor extends MatAnchor {
86141
// The FAB by default has its color set to accent.
87142
color = 'accent' as ThemePalette;
88143

89-
extended: boolean;
144+
private _extended: boolean;
145+
get extended() { return this._extended; }
146+
set extended(extended: any) { this._extended = coerceBooleanProperty(extended); }
90147

91148
constructor(
92149
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
93150
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
94151
super(elementRef, platform, ngZone, animationMode);
95152
}
96153
}
154+
155+
/**
156+
* Material Design mini floating action button (FAB) component for anchor elements. Anchor elements
157+
* are used to provide links for the user to navigate across different routes or pages.
158+
* See https://material.io/components/buttons-floating-action-button/
159+
*/
160+
@Component({
161+
selector: `a[mat-mini-fab]`,
162+
templateUrl: 'button.html',
163+
styleUrls: ['fab.css'],
164+
inputs: MAT_ANCHOR_INPUTS,
165+
host: MAT_ANCHOR_HOST,
166+
exportAs: 'matButton, matAnchor',
167+
encapsulation: ViewEncapsulation.None,
168+
changeDetection: ChangeDetectionStrategy.OnPush,
169+
})
170+
export class MatMiniFabAnchor extends MatAnchor {
171+
// The FAB by default has its color set to accent.
172+
color = 'accent' as ThemePalette;
173+
174+
constructor(
175+
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
176+
@Optional() @Inject(ANIMATION_MODULE_TYPE) animationMode?: string) {
177+
super(elementRef, platform, ngZone, animationMode);
178+
}
179+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {NgModule} from '@angular/core';
1010
import {MatCommonModule, MatRippleModule} from '@angular/material-experimental/mdc-core';
1111
import {MatAnchor, MatButton} from './button';
12-
import {MatFabAnchor, MatFabButton} from './fab';
12+
import {MatFabAnchor, MatFabButton, MatMiniFabAnchor, MatMiniFabButton} from './fab';
1313
import {MatIconAnchor, MatIconButton} from './icon-button';
1414

1515
@NgModule({
@@ -19,6 +19,8 @@ import {MatIconAnchor, MatIconButton} from './icon-button';
1919
MatButton,
2020
MatIconAnchor,
2121
MatIconButton,
22+
MatMiniFabAnchor,
23+
MatMiniFabButton,
2224
MatFabAnchor,
2325
MatFabButton,
2426
MatCommonModule,
@@ -27,6 +29,8 @@ import {MatIconAnchor, MatIconButton} from './icon-button';
2729
MatAnchor,
2830
MatButton,
2931
MatIconAnchor,
32+
MatMiniFabAnchor,
33+
MatMiniFabButton,
3034
MatIconButton,
3135
MatFabAnchor,
3236
MatFabButton,

0 commit comments

Comments
 (0)