Skip to content

Commit 4f32240

Browse files
committed
Server-side rendering improvements
1 parent 9bca05f commit 4f32240

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

src/lib/button/button.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ describe('MdButton', () => {
6262

6363
});
6464

65+
describe('button[md-fab]', () => {
66+
it('should have accent palette by default', () => {
67+
const fixture = TestBed.createComponent(TestApp);
68+
const fabButtonDebugEl = fixture.debugElement.query(By.css('button[md-fab]'));
69+
70+
fixture.detectChanges();
71+
72+
expect(fabButtonDebugEl.nativeElement.classList)
73+
.toContain('mat-accent', 'Expected fab buttons to use accent palette by default');
74+
});
75+
});
76+
77+
describe('button[md-mini-fab]', () => {
78+
it('should have accent palette by default', () => {
79+
const fixture = TestBed.createComponent(TestApp);
80+
const miniFabButtonDebugEl = fixture.debugElement.query(By.css('button[md-mini-fab]'));
81+
82+
fixture.detectChanges();
83+
84+
expect(miniFabButtonDebugEl.nativeElement.classList)
85+
.toContain('mat-accent', 'Expected mini-fab buttons to use accent palette by default');
86+
});
87+
});
88+
6589
// Regular button tests
6690
describe('button[md-button]', () => {
6791
it('should handle a click on the button', () => {
@@ -218,6 +242,8 @@ describe('MdButton', () => {
218242
Go
219243
</button>
220244
<a href="http://www.google.com" md-button [disabled]="isDisabled" [color]="buttonColor">Link</a>
245+
<button md-fab>Fab Button</button>
246+
<button md-mini-fab>Mini Fab Button</button>
221247
`
222248
})
223249
class TestApp {

src/lib/button/button.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
HostBinding,
77
Input,
88
OnDestroy,
9+
Optional,
910
Renderer2,
11+
Self,
1012
ViewEncapsulation
1113
} from '@angular/core';
1214
import {coerceBooleanProperty, FocusOriginMonitor, Platform} from '../core';
@@ -15,6 +17,9 @@ import {mixinDisabled, CanDisable} from '../core/common-behaviors/disabled';
1517

1618
// TODO(kara): Convert attribute selectors to classes when attr maps become available
1719

20+
/** Default color palette for round buttons (md-fab and md-mini-fab) */
21+
const DEFAULT_ROUND_BUTTON_COLOR = 'accent';
22+
1823

1924
/**
2025
* Directive whose purpose is to add the mat- CSS styling to this selector.
@@ -57,17 +62,28 @@ export class MdIconButtonCssMatStyler {}
5762
selector: 'button[md-fab], button[mat-fab], a[md-fab], a[mat-fab]',
5863
host: {'class': 'mat-fab'}
5964
})
60-
export class MdFabCssMatStyler {}
65+
export class MdFab {
66+
constructor(@Self() @Optional() button: MdButton, @Self() @Optional() anchor: MdAnchor) {
67+
// Set the default color palette for the md-fab components.
68+
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
69+
}
70+
}
6171

6272
/**
63-
* Directive whose purpose is to add the mat- CSS styling to this selector.
73+
* Directive that targets mini-fab buttons and anchors. It's used to apply the `mat-` class
74+
* to all mini-fab buttons and also is responsible for setting the default color palette.
6475
* @docs-private
6576
*/
6677
@Directive({
6778
selector: 'button[md-mini-fab], button[mat-mini-fab], a[md-mini-fab], a[mat-mini-fab]',
6879
host: {'class': 'mat-mini-fab'}
6980
})
70-
export class MdMiniFabCssMatStyler {}
81+
export class MdMiniFab {
82+
constructor(@Self() @Optional() button: MdButton, @Self() @Optional() anchor: MdAnchor) {
83+
// Set the default color palette for the md-mini-fab components.
84+
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
85+
}
86+
}
7187

7288

7389
// Boilerplate for applying mixins to MdButton.
@@ -117,10 +133,6 @@ export class MdButton extends _MdButtonMixinBase implements OnDestroy, CanDisabl
117133
private _focusOriginMonitor: FocusOriginMonitor) {
118134
super();
119135
this._focusOriginMonitor.monitor(this._elementRef.nativeElement, this._renderer, true);
120-
121-
if (this._isRoundButton) {
122-
this.color = 'accent';
123-
}
124136
}
125137

126138
ngOnDestroy() {

src/lib/button/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {MdCommonModule, MdRippleModule, StyleModule} from '../core';
44
import {
55
MdAnchor,
66
MdButton,
7+
MdMiniFab,
78
MdButtonCssMatStyler,
8-
MdFabCssMatStyler,
9+
MdFab,
910
MdIconButtonCssMatStyler,
10-
MdMiniFabCssMatStyler,
1111
MdRaisedButtonCssMatStyler
1212
} from './button';
1313

@@ -25,21 +25,21 @@ export * from './button';
2525
exports: [
2626
MdButton,
2727
MdAnchor,
28+
MdMiniFab,
29+
MdFab,
2830
MdCommonModule,
2931
MdButtonCssMatStyler,
3032
MdRaisedButtonCssMatStyler,
3133
MdIconButtonCssMatStyler,
32-
MdFabCssMatStyler,
33-
MdMiniFabCssMatStyler,
3434
],
3535
declarations: [
3636
MdButton,
3737
MdAnchor,
38+
MdMiniFab,
39+
MdFab,
3840
MdButtonCssMatStyler,
3941
MdRaisedButtonCssMatStyler,
4042
MdIconButtonCssMatStyler,
41-
MdFabCssMatStyler,
42-
MdMiniFabCssMatStyler,
4343
],
4444
})
4545
export class MdButtonModule {}

0 commit comments

Comments
 (0)