chore(material): clean up old workarounds with new features.

This commit is contained in:
Jeremy Elbourn
2015-08-06 17:54:34 -07:00
parent 7c52bc9768
commit bd498977bd
21 changed files with 223 additions and 227 deletions
@@ -1,19 +1,17 @@
import {Component, View, ViewEncapsulation, Attribute} from 'angular2/angular2';
import {isPresent} from 'angular2/src/facade/lang';
import {KEY_SPACE} from 'angular2_material/src/core/constants';
import {KeyboardEvent} from 'angular2/src/facade/browser';
import {NumberWrapper} from 'angular2/src/facade/lang';
import {MdCheckbox} from "../checkbox/checkbox";
// TODO(jelbourn): without gesture support, this is identical to MdCheckbox.
// TODO(jelbourn): add gesture support
// TODO(jelbourn): clean up CSS.
@Component({
selector: 'md-switch',
properties: ['checked', 'disabled'],
host: {
'(keydown)': 'onKeydown($event)',
'role': 'checkbox',
'[attr.aria-checked]': 'checked',
'[attr.aria-disabled]': 'disabled_',
'[attr.role]': '"checkbox"'
'(keydown)': 'onKeydown($event)',
}
})
@View({
@@ -21,41 +19,8 @@ import {NumberWrapper} from 'angular2/src/facade/lang';
directives: [],
encapsulation: ViewEncapsulation.NONE
})
export class MdSwitch {
/** Whether this switch is checked. */
checked: boolean;
/** Whether this switch is disabled. */
disabled_: boolean;
tabindex: number;
export class MdSwitch extends MdCheckbox {
constructor(@Attribute('tabindex') tabindex: string) {
this.checked = false;
this.tabindex = isPresent(tabindex) ? NumberWrapper.parseInt(tabindex, 10) : 0;
}
get disabled() {
return this.disabled_;
}
set disabled(value) {
this.disabled_ = isPresent(value) && value !== false;
}
onKeydown(event: KeyboardEvent) {
if (event.keyCode === KEY_SPACE) {
event.preventDefault();
this.toggle(event);
}
}
toggle(event) {
if (this.disabled) {
event.stopPropagation();
return;
}
this.checked = !this.checked;
super(tabindex);
}
}