Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkbox): Add value attribute to md-checkbox #2701

Merged
merged 2 commits into from
Mar 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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