diff --git a/ionic/components/button/test/button.spec.ts b/ionic/components/button/test/button.spec.ts
index e72be680da..a7c17093ca 100644
--- a/ionic/components/button/test/button.spec.ts
+++ b/ionic/components/button/test/button.spec.ts
@@ -2,6 +2,183 @@ import {Button, Config} from 'ionic/ionic';
export function run() {
+ describe('button', () => {
+
+ it('should ignore certain attributes', () => {
+ let b = mockButton(['_ngcontent', 'button']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-_ngcontent')).toEqual(false);
+ expect(hasClass(b, 'button-button')).toEqual(false);
+ });
+
+ it('should set a different button role', () => {
+ let b = mockButton(['outline', 'small', 'full', 'primary']);
+ b.setRole('bar-button');
+ b._assignCss(true);
+ expect(hasClass(b, 'bar-button-outline')).toEqual(true);
+ expect(hasClass(b, 'bar-button-small')).toEqual(true);
+ expect(hasClass(b, 'bar-button-full')).toEqual(true);
+ expect(hasClass(b, 'bar-button-outline-primary')).toEqual(true);
+
+ expect(hasClass(b, 'button-outline')).toEqual(false);
+ expect(hasClass(b, 'button-small')).toEqual(false);
+ expect(hasClass(b, 'button-full')).toEqual(false);
+ expect(hasClass(b, 'button-primary')).toEqual(false);
+ });
+
+ it('should remove button color attributes and add different role', () => {
+ let b = mockButton(['outline', 'small', 'full', 'primary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-outline')).toEqual(true);
+ expect(hasClass(b, 'button-small')).toEqual(true);
+ expect(hasClass(b, 'button-full')).toEqual(true);
+ expect(hasClass(b, 'button-outline-primary')).toEqual(true);
+
+ b._assignCss(false);
+ expect(hasClass(b, 'button-outline')).toEqual(false);
+ expect(hasClass(b, 'button-small')).toEqual(false);
+ expect(hasClass(b, 'button-full')).toEqual(false);
+ expect(hasClass(b, 'button-outline-primary')).toEqual(false);
+ });
+
+ it('should read button color attributes with styles', () => {
+ let b = mockButton(['outline', 'small', 'full', 'primary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-outline')).toEqual(true);
+ expect(hasClass(b, 'button-small')).toEqual(true);
+ expect(hasClass(b, 'button-full')).toEqual(true);
+ expect(hasClass(b, 'button-outline-primary')).toEqual(true);
+
+ b = mockButton(['clear', 'primary', 'secondary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-clear')).toEqual(true);
+ expect(hasClass(b, 'button-clear-primary')).toEqual(true);
+ expect(hasClass(b, 'button-clear-secondary')).toEqual(true);
+
+ b = mockButton(['solid', 'primary', 'secondary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-solid')).toEqual(true);
+ expect(hasClass(b, 'button-solid-primary')).toEqual(true);
+ expect(hasClass(b, 'button-solid-secondary')).toEqual(true);
+ });
+
+ it('should auto add the default style', () => {
+ let b = mockButton();
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-default')).toEqual(true);
+
+ b = mockButton(['clear']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ expect(hasClass(b, 'button-default')).toEqual(false);
+ expect(hasClass(b, 'button-clear')).toEqual(true);
+ });
+
+ it('should read button color attributes', () => {
+ let b = mockButton(['primary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-primary')).toEqual(true);
+
+ b = mockButton(['primary', 'secondary']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-primary')).toEqual(true);
+ expect(hasClass(b, 'button-secondary')).toEqual(true);
+ });
+
+ it('should read button style attributes', () => {
+ let b = mockButton(['clear']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-clear')).toEqual(true);
+
+ b = mockButton(['outline']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-outline')).toEqual(true);
+
+ b = mockButton(['clear', 'outline', 'small', 'full']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-clear')).toEqual(false);
+ expect(hasClass(b, 'button-outline')).toEqual(true);
+ expect(hasClass(b, 'button-small')).toEqual(true);
+ expect(hasClass(b, 'button-full')).toEqual(true);
+ });
+
+ it('should read button shape attributes', () => {
+ let b = mockButton(['round']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-round')).toEqual(true);
+
+ b = mockButton(['fab']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-fab')).toEqual(true);
+ });
+
+ it('should read button display attributes', () => {
+ let b = mockButton(['block']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-block')).toEqual(true);
+
+ b = mockButton(['full']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-full')).toEqual(true);
+
+ b = mockButton(['block', 'full']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-block')).toEqual(false);
+ expect(hasClass(b, 'button-full')).toEqual(true);
+ });
+
+ it('should read button size attributes', () => {
+ let b = mockButton(['small']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-small')).toEqual(true);
+
+ b = mockButton(['large']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-large')).toEqual(true);
+
+ b = mockButton(['large', 'small']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button-large')).toEqual(false);
+ expect(hasClass(b, 'button-small')).toEqual(true);
+ });
+
+ it('should not add button css class for ion-item attribute', () => {
+ let b = mockButton(['ion-item']);
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(false);
+ });
+
+ it('should add button css class', () => {
+ let b = mockButton();
+ b._assignCss(true);
+ expect(hasClass(b, 'button')).toEqual(true);
+ });
+
+ it('should add disable-hover css class', () => {
+ let config = new Config({
+ hoverCSS: false
+ });
+ let b = mockButton(null, config);
+
+ expect(hasClass(b, 'disable-hover')).toEqual(true);
+ });
+
+ it('should set defaults', () => {
+ let b = mockButton();
+ expect(b._role).toEqual('button');
+ expect(b._size).toEqual(null);
+ expect(b._colors.length).toEqual(0);
+ expect(b._style).toEqual('default');
+ expect(b._display).toEqual(null);
+ });
+
+ });
+
function mockButton(attrs, config) {
config = config || new Config();
let elementRef = {
@@ -13,188 +190,15 @@ export function run() {
}
}
let renderer = {
- setElementClass: function(elementRef, className, shouldAdd) {
- elementRef.nativeElement.classList[shouldAdd ? 'add' : 'remove'](className);
+ setElementClass: function(nativeElement, className, shouldAdd) {
+ nativeElement.classList[shouldAdd ? 'add' : 'remove'](className);
}
};
- return new Button(config, elementRef, renderer);
+ return new Button(config, elementRef, renderer, null);
}
function hasClass(button, className) {
return button._elementRef.nativeElement.classList.contains(className);
}
- it('should ignore certain attributes', () => {
- let b = mockButton(['_ngcontent', 'button']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-_ngcontent')).toEqual(false);
- expect(hasClass(b, 'button-button')).toEqual(false);
- });
-
- it('should set a different button role', () => {
- let b = mockButton(['outline', 'small', 'full', 'primary']);
- b.setRole('bar-button');
- b._assignCss(true);
- expect(hasClass(b, 'bar-button-outline')).toEqual(true);
- expect(hasClass(b, 'bar-button-small')).toEqual(true);
- expect(hasClass(b, 'bar-button-full')).toEqual(true);
- expect(hasClass(b, 'bar-button-outline-primary')).toEqual(true);
-
- expect(hasClass(b, 'button-outline')).toEqual(false);
- expect(hasClass(b, 'button-small')).toEqual(false);
- expect(hasClass(b, 'button-full')).toEqual(false);
- expect(hasClass(b, 'button-primary')).toEqual(false);
- });
-
- it('should remove button color attributes and add different role', () => {
- let b = mockButton(['outline', 'small', 'full', 'primary']);
- b._assignCss(true);
- expect(hasClass(b, 'button-outline')).toEqual(true);
- expect(hasClass(b, 'button-small')).toEqual(true);
- expect(hasClass(b, 'button-full')).toEqual(true);
- expect(hasClass(b, 'button-outline-primary')).toEqual(true);
-
- b._assignCss(false);
- expect(hasClass(b, 'button-outline')).toEqual(false);
- expect(hasClass(b, 'button-small')).toEqual(false);
- expect(hasClass(b, 'button-full')).toEqual(false);
- expect(hasClass(b, 'button-outline-primary')).toEqual(false);
- });
-
- it('should read button color attributes with styles', () => {
- let b = mockButton(['outline', 'small', 'full', 'primary']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-outline')).toEqual(true);
- expect(hasClass(b, 'button-small')).toEqual(true);
- expect(hasClass(b, 'button-full')).toEqual(true);
- expect(hasClass(b, 'button-outline-primary')).toEqual(true);
-
- b = mockButton(['clear', 'primary', 'secondary']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-clear')).toEqual(true);
- expect(hasClass(b, 'button-clear-primary')).toEqual(true);
- expect(hasClass(b, 'button-clear-secondary')).toEqual(true);
-
- b = mockButton(['solid', 'primary', 'secondary']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-solid')).toEqual(true);
- expect(hasClass(b, 'button-solid-primary')).toEqual(true);
- expect(hasClass(b, 'button-solid-secondary')).toEqual(true);
- });
-
- it('should auto add the default style', () => {
- let b = mockButton();
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-default')).toEqual(true);
-
- b = mockButton(['clear']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- expect(hasClass(b, 'button-default')).toEqual(false);
- expect(hasClass(b, 'button-clear')).toEqual(true);
- });
-
- it('should read button color attributes', () => {
- let b = mockButton(['primary']);
- b._assignCss(true);
- expect(hasClass(b, 'button-primary')).toEqual(true);
-
- b = mockButton(['primary', 'secondary']);
- b._assignCss(true);
- expect(hasClass(b, 'button-primary')).toEqual(true);
- expect(hasClass(b, 'button-secondary')).toEqual(true);
- });
-
- it('should read button style attributes', () => {
- let b = mockButton(['clear']);
- b._assignCss(true);
- expect(hasClass(b, 'button-clear')).toEqual(true);
-
- b = mockButton(['outline']);
- b._assignCss(true);
- expect(hasClass(b, 'button-outline')).toEqual(true);
-
- b = mockButton(['clear', 'outline', 'small', 'full']);
- b._assignCss(true);
- expect(hasClass(b, 'button-clear')).toEqual(false);
- expect(hasClass(b, 'button-outline')).toEqual(true);
- expect(hasClass(b, 'button-small')).toEqual(true);
- expect(hasClass(b, 'button-full')).toEqual(true);
- });
-
- it('should read button shape attributes', () => {
- let b = mockButton(['round']);
- b._assignCss(true);
- expect(hasClass(b, 'button-round')).toEqual(true);
-
- b = mockButton(['fab']);
- b._assignCss(true);
- expect(hasClass(b, 'button-fab')).toEqual(true);
- });
-
- it('should read button display attributes', () => {
- let b = mockButton(['block']);
- b._assignCss(true);
- expect(hasClass(b, 'button-block')).toEqual(true);
-
- b = mockButton(['full']);
- b._assignCss(true);
- expect(hasClass(b, 'button-full')).toEqual(true);
-
- b = mockButton(['block', 'full']);
- b._assignCss(true);
- expect(hasClass(b, 'button-block')).toEqual(false);
- expect(hasClass(b, 'button-full')).toEqual(true);
- });
-
- it('should read button size attributes', () => {
- let b = mockButton(['small']);
- b._assignCss(true);
- expect(hasClass(b, 'button-small')).toEqual(true);
-
- b = mockButton(['large']);
- b._assignCss(true);
- expect(hasClass(b, 'button-large')).toEqual(true);
-
- b = mockButton(['large', 'small']);
- b._assignCss(true);
- expect(hasClass(b, 'button-large')).toEqual(false);
- expect(hasClass(b, 'button-small')).toEqual(true);
- });
-
- it('should not add button css class for ion-item attribute', () => {
- let b = mockButton(['ion-item']);
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(false);
- });
-
- it('should add button css class', () => {
- let b = mockButton();
- b._assignCss(true);
- expect(hasClass(b, 'button')).toEqual(true);
- });
-
- it('should add disable-hover css class', () => {
- let config = new Config({
- hoverCSS: false
- });
- let b = mockButton(null, config);
-
- expect(hasClass(b, 'disable-hover')).toEqual(true);
- });
-
- it('should set defaults', () => {
- let b = mockButton();
- expect(b._role).toEqual('button');
- expect(b._size).toEqual(null);
- expect(b._colors.length).toEqual(0);
- expect(b._style).toEqual('default');
- expect(b._display).toEqual(null);
- });
-
}
diff --git a/ionic/components/checkbox/checkbox.ts b/ionic/components/checkbox/checkbox.ts
index 8fe5cbb5ba..c1feef4cac 100644
--- a/ionic/components/checkbox/checkbox.ts
+++ b/ionic/components/checkbox/checkbox.ts
@@ -3,6 +3,7 @@ import {NgControl} from 'angular2/common';
import {Form} from '../../util/form';
import {Item} from '../item/item';
+import {isTrueProperty} from '../../util/util';
/**
* The checkbox is no different than the HTML checkbox input, except
@@ -99,7 +100,7 @@ export class Checkbox {
set checked(val) {
if (!this._disabled) {
- this._checked = (val === true || val === 'true');
+ this._checked = isTrueProperty(val);
this.onChange(this._checked);
this._item && this._item.setCssClass('item-checkbox-checked', this._checked);
}
@@ -111,7 +112,7 @@ export class Checkbox {
}
set disabled(val) {
- this._disabled = (val === true || val === 'true');
+ this._disabled = isTrueProperty(val);
this._item && this._item.setCssClass('item-checkbox-disabled', this._disabled);
}
@@ -132,8 +133,10 @@ export class Checkbox {
* the checked value.
* https://github.com/angular/angular/blob/master/modules/angular2/src/forms/directives/shared.ts#L34
*/
- writeValue(value) {
- this.checked = value;
+ writeValue(val) {
+ if (val !== null) {
+ this.checked = val;
+ }
}
/**
diff --git a/ionic/components/checkbox/test/basic/main.html b/ionic/components/checkbox/test/basic/main.html
index 4badb5ec30..b7670ad5fa 100644
--- a/ionic/components/checkbox/test/basic/main.html
+++ b/ionic/components/checkbox/test/basic/main.html
@@ -30,12 +30,12 @@