Skip to content

Commit 26788f1

Browse files
crisbetoandrewseguin
authored andcommitted
fix(checkbox): defaulting to invalid name and value attributes (#7130)
Fixes the checkbox defaulting to `name="null"` and `value="undefined"` for the underlying input, if the user hasn't passed them in.
1 parent c5e162b commit 26788f1

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/lib/checkbox/checkbox.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
[id]="inputId"
77
[required]="required"
88
[checked]="checked"
9-
[value]="value"
9+
[attr.value]="value"
1010
[disabled]="disabled"
11-
[name]="name"
11+
[attr.name]="name"
1212
[tabIndex]="tabIndex"
1313
[indeterminate]="indeterminate"
1414
[attr.aria-label]="ariaLabel"

src/lib/checkbox/checkbox.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,17 @@ describe('MatCheckbox', () => {
873873
.not.toContain('mat-checkbox-inner-container-no-side-margin');
874874
}, 1);
875875
}));
876+
877+
it('should not add the "name" attribute if it is not passed in', () => {
878+
fixture.detectChanges();
879+
expect(checkboxInnerContainer.querySelector('input')!.hasAttribute('name')).toBe(false);
880+
});
881+
882+
it('should not add the "value" attribute if it is not passed in', () => {
883+
fixture.detectChanges();
884+
expect(checkboxInnerContainer.querySelector('input')!.hasAttribute('value')).toBe(false);
885+
});
886+
876887
});
877888
});
878889

src/lib/checkbox/checkbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class MatCheckbox extends _MatCheckboxMixinBase implements ControlValueAc
169169
@Output() indeterminateChange: EventEmitter<boolean> = new EventEmitter<boolean>();
170170

171171
/** The value attribute of the native input element */
172-
@Input() value: string ;
172+
@Input() value: string;
173173

174174
/** The native `<input type="checkbox"> element */
175175
@ViewChild('input') _inputElement: ElementRef;

0 commit comments

Comments
 (0)