make checkboxes work

This commit is contained in:
Andrew
2015-03-28 19:42:12 -06:00
parent e31c18311a
commit afe6fd3c8a
3 changed files with 35 additions and 17 deletions

View File

@ -1,7 +1,7 @@
import {Component, Template, NgElement, PropertySetter} from 'angular2/angular2'; import {Component, Template, NgElement, PropertySetter} from 'angular2/angular2'
import {ComponentConfig} from 'ionic2/config/component-config'; import {ComponentConfig} from 'ionic2/config/component-config'
export let CheckboxConfig = new ComponentConfig('checkbox'); export let CheckboxConfig = new ComponentConfig('checkbox')
@Component({ @Component({
selector: 'ion-checkbox', selector: 'ion-checkbox',
@ -9,7 +9,7 @@ export let CheckboxConfig = new ComponentConfig('checkbox');
checked: 'checked' checked: 'checked'
}, },
events: { events: {
'click': 'onClick' 'click': 'onClick()'
}, },
services: [CheckboxConfig] services: [CheckboxConfig]
}) })
@ -30,21 +30,36 @@ export let CheckboxConfig = new ComponentConfig('checkbox');
}) })
export class Checkbox { export class Checkbox {
constructor( constructor(
@PropertySetter('attr.role') setRole: Function,
@PropertySetter('attr.aria-checked') setChecked: Function,
@PropertySetter('attr.aria-invalid') setInvalid: Function,
@PropertySetter('attr.aria-disabled') setDisabled: Function,
configFactory: CheckboxConfig, configFactory: CheckboxConfig,
element: NgElement element: NgElement,
@PropertySetter('attr.role') setAriaRole: Function,
@PropertySetter('attr.aria-checked') setAriaChecked: Function,
@PropertySetter('attr.aria-invalid') setAriaInvalid: Function,
@PropertySetter('attr.aria-disabled') setAriaDisabled: Function
) { ) {
this.domElement = element.domElement; this.domElement = element.domElement
this.domElement.classList.add('item'); this.domElement.classList.add('item')
this.config = configFactory.create(this); this.config = configFactory.create(this)
setRole('checkbox'); setAriaRole('checkbox')
setChecked('true') setAriaInvalid('false')
setInvalid('false'); setAriaDisabled('false')
setDisabled('false');
this.setAriaRole = setAriaRole
this.setAriaChecked = setAriaChecked
this.setAriaInvalid = setAriaInvalid
this.setAriaDisabled = setAriaDisabled
}
set checked(checked) {
this._checked = checked
this.setAriaChecked(checked)
}
get checked() {
return this._checked
}
onClick() {
this.checked = !this.checked;
} }
} }

View File

@ -2,6 +2,9 @@
// Checkbox // Checkbox
// -------------------------------------------------- // --------------------------------------------------
.checkbox {
display: block;
}
.checkbox-on { .checkbox-on {
display: none; display: none;

View File

@ -8,7 +8,7 @@
<ion-list> <ion-list>
<ion-list-header>Some Checkboxes</ion-list-header> <ion-list-header>Some Checkboxes</ion-list-header>
<ion-checkbox> <ion-checkbox [checked]="true">
Apples Apples
</ion-checkbox> </ion-checkbox>