Skip to content

Commit f3c097e

Browse files
committed
all expect sidenav
1 parent ab693d1 commit f3c097e

File tree

11 files changed

+131
-92
lines changed

11 files changed

+131
-92
lines changed

src/lib/button-toggle/button-toggle.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
FormsModule,
2222
} from '@angular/forms';
2323
import {Observable} from 'rxjs/Observable';
24-
import {BooleanFieldValue, MdUniqueSelectionDispatcher} from '@angular2-material/core';
24+
import {MdUniqueSelectionDispatcher} from '@angular2-material/core';
25+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2526

2627
export type ToggleType = 'checkbox' | 'radio';
2728

@@ -101,13 +102,12 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
101102
}
102103

103104
@Input()
104-
@BooleanFieldValue()
105105
get disabled(): boolean {
106106
return this._disabled;
107107
}
108108

109109
set disabled(value) {
110-
this._disabled = (value != null && value !== false) ? true : null;
110+
this._disabled = coerceBooleanProperty(value);
111111
}
112112

113113
@Input()

src/lib/button/button.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
ModuleWithProviders,
1111
} from '@angular/core';
1212
import {CommonModule} from '@angular/common';
13-
import {BooleanFieldValue} from '@angular2-material/core';
1413
import {MdRippleModule} from '@angular2-material/core';
14+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
1515

1616
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
1717
// TODO(kara): Convert attribute selectors to classes when attr maps become available
@@ -42,7 +42,11 @@ export class MdButton {
4242
_isMouseDown: boolean = false;
4343

4444
/** Whether the ripple effect on click should be disabled. */
45-
@Input() @BooleanFieldValue() disableRipple: boolean = false;
45+
private _disableRipple: boolean = false;
46+
47+
@Input()
48+
get disableRipple() { return this._disableRipple; }
49+
set disableRipple(v) { this._disableRipple = coerceBooleanProperty(v); }
4650

4751
constructor(private _elementRef: ElementRef, private _renderer: Renderer) { }
4852

src/lib/core/annotations/field-value.spec.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/lib/core/annotations/field-value.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {coerceBooleanProperty} from './boolean-property';
2+
3+
4+
describe('coerceBooleanProperty', () => {
5+
it('should coerce undefined to false', () => {
6+
expect(coerceBooleanProperty(undefined)).toBe(false);
7+
});
8+
9+
it('should coerce null to false', () => {
10+
expect(coerceBooleanProperty(null)).toBe(false);
11+
});
12+
13+
it('should coerce the empty string to true', () => {
14+
expect(coerceBooleanProperty('')).toBe(true);
15+
});
16+
17+
it('should coerce zero to true', () => {
18+
expect(coerceBooleanProperty(0)).toBe(true);
19+
});
20+
21+
it('should coerce the string "false" to false', () => {
22+
expect(coerceBooleanProperty('false')).toBe(false);
23+
});
24+
25+
it('should coerce the boolean false to false', () => {
26+
expect(coerceBooleanProperty(false)).toBe(false);
27+
});
28+
29+
it('should coerce the boolean true to true', () => {
30+
expect(coerceBooleanProperty(true)).toBe(true);
31+
});
32+
33+
it('should coerce the string "true" to true', () => {
34+
expect(coerceBooleanProperty('true')).toBe(true);
35+
});
36+
37+
it('should coerce an arbitrary string to true', () => {
38+
expect(coerceBooleanProperty('pink')).toBe(true);
39+
});
40+
41+
it('should coerce an object to true', () => {
42+
expect(coerceBooleanProperty({})).toBe(true);
43+
});
44+
45+
it('should coerce an array to true', () => {
46+
expect(coerceBooleanProperty([])).toBe(true);
47+
});
48+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** Coerces a data-bound value (typically a string) to a boolean. */
2+
export function coerceBooleanProperty(value: any): boolean {
3+
return value != null && `${value}` !== 'false';
4+
}

src/lib/core/core.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ export {applyCssTransform} from './style/apply-transform';
6363
// Error
6464
export {MdError} from './errors/error';
6565

66-
// Annotations.
67-
export {BooleanFieldValue} from './annotations/field-value';
68-
6966
// Misc
7067
export {ComponentType} from './overlay/generic-component-type';
7168

src/lib/input/input.ts

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import {
2424
FormsModule,
2525
} from '@angular/forms';
2626
import {CommonModule} from '@angular/common';
27-
import {BooleanFieldValue, MdError} from '@angular2-material/core';
27+
import {MdError} from '@angular2-material/core';
2828
import {Observable} from 'rxjs/Observable';
29+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2930

3031

3132
const noop = () => {};
@@ -118,9 +119,22 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
118119
*/
119120
@Input('aria-label') ariaLabel: string;
120121
@Input('aria-labelledby') ariaLabelledBy: string;
121-
@Input('aria-disabled') @BooleanFieldValue() ariaDisabled: boolean;
122-
@Input('aria-required') @BooleanFieldValue() ariaRequired: boolean;
123-
@Input('aria-invalid') @BooleanFieldValue() ariaInvalid: boolean;
122+
123+
private _ariaDisabled: boolean;
124+
private _ariaRequired: boolean;
125+
private _ariaInvalid: boolean;
126+
127+
@Input('aria-disabled')
128+
get ariaDisabled(): boolean { return this._ariaDisabled; }
129+
set ariaDisabled(value) { this._ariaDisabled = coerceBooleanProperty(value); }
130+
131+
@Input('aria-required')
132+
get ariaRequired(): boolean { return this._ariaRequired; }
133+
set ariaRequired(value) { this._ariaRequired = coerceBooleanProperty(value); }
134+
135+
@Input('aria-invalid')
136+
get ariaInvalid(): boolean { return this._ariaInvalid; }
137+
set ariaInvalid(value) { this._ariaInvalid = coerceBooleanProperty(value); }
124138

125139
/**
126140
* Content directives.
@@ -141,29 +155,55 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
141155
*/
142156
@Input() align: 'start' | 'end' = 'start';
143157
@Input() dividerColor: 'primary' | 'accent' | 'warn' = 'primary';
144-
@Input() @BooleanFieldValue() floatingPlaceholder: boolean = true;
145158
@Input() hintLabel: string = '';
146159

147160
@Input() autocomplete: string;
148161
@Input() autocorrect: string;
149162
@Input() autocapitalize: string;
150-
@Input() @BooleanFieldValue() autofocus: boolean = false;
151-
@Input() @BooleanFieldValue() disabled: boolean = false;
152163
@Input() id: string = `md-input-${nextUniqueId++}`;
153164
@Input() list: string = null;
154165
@Input() max: string | number = null;
155166
@Input() maxlength: number = null;
156167
@Input() min: string | number = null;
157168
@Input() minlength: number = null;
158169
@Input() placeholder: string = null;
159-
@Input() @BooleanFieldValue() readonly: boolean = false;
160-
@Input() @BooleanFieldValue() required: boolean = false;
161-
@Input() @BooleanFieldValue() spellcheck: boolean = false;
162170
@Input() step: number = null;
163171
@Input() tabindex: number = null;
164172
@Input() type: string = 'text';
165173
@Input() name: string = null;
166174

175+
private _floatingPlaceholder: boolean;
176+
private _autofocus: boolean;
177+
private _disabled: boolean;
178+
private _readonly: boolean;
179+
private _required: boolean;
180+
private _spellcheck: boolean;
181+
182+
@Input()
183+
get floatingPlaceholder(): boolean { return this._floatingPlaceholder; }
184+
set floatingPlaceholder(value) { this._floatingPlaceholder = coerceBooleanProperty(value); }
185+
186+
@Input()
187+
get autofocus(): boolean { return this._autofocus; }
188+
set autofocus(value) { this._autofocus = coerceBooleanProperty(value); }
189+
190+
@Input()
191+
get disabled(): boolean { return this._disabled; }
192+
set disabled(value) { this._disabled = coerceBooleanProperty(value); }
193+
194+
@Input()
195+
get readonly(): boolean { return this._readonly; }
196+
set readonly(value) { this._readonly = coerceBooleanProperty(value); }
197+
198+
@Input()
199+
get required(): boolean { return this._required; }
200+
set required(value) { this._required = coerceBooleanProperty(value); }
201+
202+
@Input()
203+
get spellcheck(): boolean { return this._spellcheck; }
204+
set spellcheck(value) { this._spellcheck = coerceBooleanProperty(value); }
205+
206+
167207
private _blurEmitter: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();
168208
private _focusEmitter: EventEmitter<FocusEvent> = new EventEmitter<FocusEvent>();
169209

src/lib/slide-toggle/slide-toggle.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {
1717
ControlValueAccessor,
1818
NG_VALUE_ACCESSOR
1919
} from '@angular/forms';
20-
import {BooleanFieldValue, applyCssTransform} from '@angular2-material/core';
20+
import {applyCssTransform} from '@angular2-material/core';
2121
import {Observable} from 'rxjs/Observable';
2222
import {MdGestureConfig} from '@angular2-material/core';
23+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2324

2425

2526
export const MD_SLIDE_TOGGLE_VALUE_ACCESSOR: any = {
@@ -65,13 +66,18 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
6566
private _isMousedown: boolean = false;
6667
private _slideRenderer: SlideToggleRenderer = null;
6768

68-
@Input() @BooleanFieldValue() disabled: boolean = false;
6969
@Input() name: string = null;
7070
@Input() id: string = this._uniqueId;
7171
@Input() tabIndex: number = 0;
7272
@Input() ariaLabel: string = null;
7373
@Input() ariaLabelledby: string = null;
7474

75+
private _disabled: boolean = false;
76+
77+
@Input()
78+
get disabled(): boolean { return this._disabled; }
79+
set disabled(value) { this._disabled = coerceBooleanProperty(value); }
80+
7581
private _change: EventEmitter<MdSlideToggleChange> = new EventEmitter<MdSlideToggleChange>();
7682
@Output() change: Observable<MdSlideToggleChange> = this._change.asObservable();
7783

src/lib/slider/slider.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import {
1515
FormsModule,
1616
} from '@angular/forms';
1717
import {HAMMER_GESTURE_CONFIG} from '@angular/platform-browser';
18-
import {BooleanFieldValue, MdGestureConfig, applyCssTransform} from '@angular2-material/core';
18+
import {MdGestureConfig, applyCssTransform} from '@angular2-material/core';
1919
import {Input as HammerInput} from 'hammerjs';
20+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2021

2122
/**
2223
* Visually, a 30px separation between tick marks looks best. This is very subjective but it is
@@ -58,16 +59,20 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
5859
/** The dimensions of the slider. */
5960
private _sliderDimensions: ClientRect = null;
6061

62+
private _disabled: boolean = false;
63+
6164
@Input()
62-
@BooleanFieldValue()
6365
@HostBinding('class.md-slider-disabled')
6466
@HostBinding('attr.aria-disabled')
65-
disabled: boolean = false;
67+
get disabled(): boolean { return this._disabled; }
68+
set disabled(value) { this._disabled = coerceBooleanProperty(value); }
6669

6770
/** Whether or not to show the thumb label. */
71+
private _thumbLabel: boolean = false;
72+
6873
@Input('thumb-label')
69-
@BooleanFieldValue()
70-
thumbLabel: boolean = false;
74+
get thumbLabel(): boolean { return this._thumbLabel; }
75+
set thumbLabel(value) { this._thumbLabel = coerceBooleanProperty(value); }
7176

7277
/** The miniumum value that the slider can have. */
7378
private _min: number = 0;

src/lib/tabs/tabs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {MdInkBar} from './ink-bar';
2121
import {Observable} from 'rxjs/Observable';
2222
import 'rxjs/add/operator/map';
2323
import {RIGHT_ARROW, LEFT_ARROW, ENTER} from '@angular2-material/core';
24+
import {coerceBooleanProperty} from '../core/coersion/boolean-property';
2425

2526
/** Used to generate unique ID's for each tab component */
2627
let nextId = 0;
@@ -38,11 +39,10 @@ export class MdTab {
3839
@ContentChild(MdTabLabel) label: MdTabLabel;
3940
@ContentChild(MdTabContent) content: MdTabContent;
4041

41-
// TODO: Replace this when BooleanFieldValue is removed.
4242
private _disabled = false;
4343
@Input('disabled')
4444
set disabled(value: boolean) {
45-
this._disabled = (value != null && `${value}` !== 'false');
45+
this._disabled = coerceBooleanProperty(value);
4646
}
4747
get disabled(): boolean {
4848
return this._disabled;

0 commit comments

Comments
 (0)