Skip to content

Commit fb565c0

Browse files
tinayuangaokara
authored andcommitted
feat(checkbox): add value attribute to md-checkbox (#2701)
Fixes #2583
1 parent f4323b2 commit fb565c0

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/demo-app/checkbox/checkbox-demo.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<h1>md-checkbox: Basic Example</h1>
22
<form>
33
<md-checkbox [(ngModel)]="isChecked"
4-
name="cb"
4+
name="cb"
5+
value="basic_checkbox"
56
[color]="checkboxColor()"
67
(change)="isIndeterminate = false"
78
[indeterminate]="isIndeterminate"

src/lib/checkbox/checkbox.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[id]="inputId"
66
[required]="required"
77
[checked]="checked"
8+
[value]="value"
89
[disabled]="disabled"
910
[name]="name"
1011
[tabIndex]="tabIndex"

src/lib/checkbox/checkbox.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,13 @@ describe('MdCheckbox', () => {
314314
expect(document.activeElement).toBe(inputElement);
315315
});
316316

317+
it('should forward the value to input element', () => {
318+
testComponent.checkboxValue = 'basic_checkbox';
319+
fixture.detectChanges();
320+
321+
expect(inputElement.value).toBe('basic_checkbox');
322+
});
323+
317324
describe('ripple elements', () => {
318325

319326
it('should show ripples on label mousedown', () => {
@@ -349,7 +356,6 @@ describe('MdCheckbox', () => {
349356
expect(checkboxNativeElement.querySelectorAll('[md-ripple]').length)
350357
.toBe(1, 'Expect [md-ripple] in checkbox');
351358
}));
352-
353359
});
354360

355361
describe('color behaviour', () => {
@@ -694,6 +700,7 @@ describe('MdCheckbox', () => {
694700
[disabled]="isDisabled"
695701
[color]="checkboxColor"
696702
[disableRipple]="disableRipple"
703+
[value]="checkboxValue"
697704
(change)="changeCount = changeCount + 1"
698705
(click)="onCheckboxClick($event)"
699706
(change)="onCheckboxChange($event)">
@@ -713,6 +720,7 @@ class SingleCheckbox {
713720
lastKeydownEvent: Event = null;
714721
changeCount: number = 0;
715722
checkboxColor: string = 'primary';
723+
checkboxValue: string = 'single_checkbox';
716724

717725
onCheckboxClick(event: Event) {}
718726
onCheckboxChange(event: MdCheckboxChange) {}

src/lib/checkbox/checkbox.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ export class MdCheckbox implements ControlValueAccessor {
151151
/** Event emitted when the checkbox's `indeterminate` value changes. */
152152
@Output() indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();
153153

154+
/** The value attribute of the native input element */
155+
@Input() value: string ;
156+
154157
/** The native `<input type="checkbox"> element */
155158
@ViewChild('input') _inputElement: ElementRef;
156159

0 commit comments

Comments
 (0)