Skip to content

Commit 3903848

Browse files
committed
fix(radio-button): underlying input not respecting value binding
Currently a `mat-radio-button` does not respect the value binding that has been set on the radio-button. This is not ideal because in most cases the value is a primitive that can be set as `value` for the underlying input element in order to ensure that proper `FormData` can be retrieved when the form gets submitted. Currently the form data will always have `on` as value because the selected radio-button does not pass-through the value to the underlying input.
1 parent 4d06a1f commit 3903848

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/material/radio/radio.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
[disabled]="disabled"
2222
[tabIndex]="tabIndex"
2323
[attr.name]="name"
24+
[attr.value]="value"
2425
[required]="required"
2526
[attr.aria-label]="ariaLabel"
2627
[attr.aria-labelledby]="ariaLabelledby"

src/material/radio/radio.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ describe('MatRadio', () => {
657657
expect(radioInstance.required).toBe(true);
658658
});
659659

660+
it('should add value attribute to the underlying input element', () => {
661+
expect(fruitRadioNativeInputs[0].getAttribute('value')).toBe('banana');
662+
expect(fruitRadioNativeInputs[1].getAttribute('value')).toBe('raspberry');
663+
});
664+
660665
it('should add aria-label attribute to the underlying input element if defined', () => {
661666
expect(fruitRadioNativeInputs[0].getAttribute('aria-label')).toBe('Banana');
662667
});

0 commit comments

Comments
 (0)