Skip to content

Commit cbeb436

Browse files
committed
fix(material-experimental/mdc-button): add getter/setter for extended property
1 parent 54df3a8 commit cbeb436

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ <h4 class="demo-section-header">Anchors</h4>
3737
<a href="//www.google.com" mat-mini-fab>
3838
<mat-icon>check</mat-icon>
3939
</a>
40-
<a href="//www.google.com" mat-fab [extended]="true">Search</a>
41-
<a href="//www.google.com" mat-fab [extended]="true">
40+
<a href="//www.google.com" mat-fab extended>Search</a>
41+
<a href="//www.google.com" mat-fab extended>
4242
<mat-icon>check</mat-icon>
4343
Search
4444
</a>
@@ -54,8 +54,8 @@ <h4 class="demo-section-header">Anchors</h4>
5454
<a href="//www.google.com" disabled mat-mini-fab>
5555
<mat-icon>check</mat-icon>
5656
</a>
57-
<a href="//www.google.com" disabled mat-fab [extended]="true">Search</a>
58-
<a href="//www.google.com" disabled mat-fab [extended]="true">
57+
<a href="//www.google.com" disabled mat-fab extended>Search</a>
58+
<a href="//www.google.com" disabled mat-fab extended>
5959
<mat-icon>check</mat-icon>
6060
Search
6161
</a>
@@ -157,15 +157,15 @@ <h4 class="demo-section-header">Fab Buttons [mat-fab]</h4>
157157

158158
<h4 class="demo-section-header">Extended Fab Buttons</h4>
159159
<section>
160-
<button mat-fab [extended]="true">Extended</button>
161-
<button mat-fab [extended]="true" color="primary">Extended</button>
162-
<button mat-fab [extended]="true" color="accent">Extended</button>
163-
<button mat-fab [extended]="true" color="warn">Extended</button>
164-
<button mat-fab [extended]="true">
160+
<button mat-fab extended>Extended</button>
161+
<button mat-fab extended color="primary">Extended</button>
162+
<button mat-fab extended color="accent">Extended</button>
163+
<button mat-fab extended color="warn">Extended</button>
164+
<button mat-fab extended>
165165
<mat-icon>home</mat-icon>
166166
Extended
167167
</button>
168-
<button mat-fab [extended]="true">
168+
<button mat-fab extended>
169169
<mat-icon>home</mat-icon>
170170
Extended
171171
<mat-icon iconPositionEnd>favorite</mat-icon>

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,18 @@ describe('MDC-based MatButton', () => {
9595
});
9696

9797
describe('button[mat-fab] extended', () => {
98-
it('should have accent palette by default', () => {
98+
it('should be extended', () => {
9999
const fixture = TestBed.createComponent(TestApp);
100-
const extendedFabButtonDebugEl = fixture.debugElement.query(By.css('.mat-mdc-extended-fab'))!;
101-
102100
fixture.detectChanges();
101+
const extendedFabButtonDebugEl = fixture.debugElement.query(By.css('.extended-fab-test'))!;
102+
103+
expect(extendedFabButtonDebugEl.nativeElement.classList.contains('mat-mdc-extended-fab'))
104+
.toBeFalse();
103105

104-
expect(extendedFabButtonDebugEl.nativeElement.classList)
105-
.toContain('mat-accent', 'Expected extended fab buttons to use accent palette by default');
106+
fixture.componentInstance.extended = true;
107+
108+
fixture.detectChanges();
109+
expect(extendedFabButtonDebugEl.nativeElement.classList).toContain('mat-mdc-extended-fab');
106110
});
107111
});
108112

@@ -293,7 +297,7 @@ describe('MDC-based MatButton', () => {
293297
Link
294298
</a>
295299
<button mat-fab>Fab Button</button>
296-
<button mat-fab [extended]="true">Extended</button>
300+
<button mat-fab [extended]="extended" class="extended-fab-test">Extended</button>
297301
<button mat-mini-fab>Mini Fab Button</button>
298302
`
299303
})
@@ -303,6 +307,7 @@ class TestApp {
303307
rippleDisabled: boolean = false;
304308
buttonColor: ThemePalette;
305309
tabIndex: number;
310+
extended: boolean = false;
306311

307312
increment() {
308313
this.clickCount++;

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

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

3232
/**
3333
* Material Design floating action button (FAB) component. These buttons represent the primary
@@ -63,7 +63,9 @@ export class MatFabButton extends MatButtonBase {
6363
// The FAB by default has its color set to accent.
6464
color = 'accent' as ThemePalette;
6565

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

6870
constructor(
6971
elementRef: ElementRef, platform: Platform, ngZone: NgZone,
@@ -141,7 +143,10 @@ export class MatFabAnchor extends MatAnchor {
141143
// The FAB by default has its color set to accent.
142144
color = 'accent' as ThemePalette;
143145

144-
extended: boolean;
146+
private _extended: boolean;
147+
get extended(): boolean { return this._extended; }
148+
set extended(value: boolean) { this._extended = coerceBooleanProperty(value); }
149+
145150

146151
constructor(
147152
elementRef: ElementRef, platform: Platform, ngZone: NgZone,

0 commit comments

Comments
 (0)