feat(checkbox): add value attribute to md-checkbox (#2701)

Fixes #2583
This commit is contained in:
tinayuangao
2017-03-03 17:20:00 -08:00
committed by Kara
parent f4323b2c0f
commit fb565c0117
4 changed files with 15 additions and 2 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
<h1>md-checkbox: Basic Example</h1>
<form>
<md-checkbox [(ngModel)]="isChecked"
name="cb"
name="cb"
value="basic_checkbox"
[color]="checkboxColor()"
(change)="isIndeterminate = false"
[indeterminate]="isIndeterminate"
+1
View File
@@ -5,6 +5,7 @@
[id]="inputId"
[required]="required"
[checked]="checked"
[value]="value"
[disabled]="disabled"
[name]="name"
[tabIndex]="tabIndex"
+9 -1
View File
@@ -314,6 +314,13 @@ describe('MdCheckbox', () => {
expect(document.activeElement).toBe(inputElement);
});
it('should forward the value to input element', () => {
testComponent.checkboxValue = 'basic_checkbox';
fixture.detectChanges();
expect(inputElement.value).toBe('basic_checkbox');
});
describe('ripple elements', () => {
it('should show ripples on label mousedown', () => {
@@ -349,7 +356,6 @@ describe('MdCheckbox', () => {
expect(checkboxNativeElement.querySelectorAll('[md-ripple]').length)
.toBe(1, 'Expect [md-ripple] in checkbox');
}));
});
describe('color behaviour', () => {
@@ -694,6 +700,7 @@ describe('MdCheckbox', () => {
[disabled]="isDisabled"
[color]="checkboxColor"
[disableRipple]="disableRipple"
[value]="checkboxValue"
(change)="changeCount = changeCount + 1"
(click)="onCheckboxClick($event)"
(change)="onCheckboxChange($event)">
@@ -713,6 +720,7 @@ class SingleCheckbox {
lastKeydownEvent: Event = null;
changeCount: number = 0;
checkboxColor: string = 'primary';
checkboxValue: string = 'single_checkbox';
onCheckboxClick(event: Event) {}
onCheckboxChange(event: MdCheckboxChange) {}
+3
View File
@@ -151,6 +151,9 @@ export class MdCheckbox implements ControlValueAccessor {
/** Event emitted when the checkbox's `indeterminate` value changes. */
@Output() indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();
/** The value attribute of the native input element */
@Input() value: string ;
/** The native `<input type="checkbox"> element */
@ViewChild('input') _inputElement: ElementRef;