Skip to content

Commit

Permalink
feat(checkbox): add value attribute to md-checkbox (#2701)
Browse files Browse the repository at this point in the history
Fixes #2583
  • Loading branch information
tinayuangao authored and kara committed Mar 4, 2017
1 parent f4323b2 commit fb565c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/demo-app/checkbox/checkbox-demo.html
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/lib/checkbox/checkbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[id]="inputId"
[required]="required"
[checked]="checked"
[value]="value"
[disabled]="disabled"
[name]="name"
[tabIndex]="tabIndex"
Expand Down
10 changes: 9 additions & 1 deletion src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -349,7 +356,6 @@ describe('MdCheckbox', () => {
expect(checkboxNativeElement.querySelectorAll('[md-ripple]').length)
.toBe(1, 'Expect [md-ripple] in checkbox');
}));

});

describe('color behaviour', () => {
Expand Down Expand Up @@ -694,6 +700,7 @@ describe('MdCheckbox', () => {
[disabled]="isDisabled"
[color]="checkboxColor"
[disableRipple]="disableRipple"
[value]="checkboxValue"
(change)="changeCount = changeCount + 1"
(click)="onCheckboxClick($event)"
(change)="onCheckboxChange($event)">
Expand All @@ -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) {}
Expand Down
3 changes: 3 additions & 0 deletions src/lib/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fb565c0

Please sign in to comment.