fix(radio): dispatches input event on select

PiperOrigin-RevId: 565522665
This commit is contained in:
Elizabeth Mitchell 2023-09-14 17:25:19 -07:00 committed by Copybara-Service
parent 116b448639
commit e444de3c02
2 changed files with 17 additions and 0 deletions

View File

@ -155,6 +155,8 @@ export class Radio extends LitElement {
// Per spec, clicking on a radio input always selects it.
this.checked = true;
this.dispatchEvent(new Event('change', {bubbles: true}));
this.dispatchEvent(
new InputEvent('input', {bubbles: true, composed: true}));
}
private async handleKeydown(event: KeyboardEvent) {

View File

@ -139,6 +139,21 @@ describe('<md-radio>', () => {
expect(changeHandler).toHaveBeenCalledTimes(1);
expect(changeHandler).toHaveBeenCalledWith(jasmine.any(Event));
});
it('Should trigger input event when a radio is selected', async () => {
const {harnesses, root} = await setupTest(radioGroupPreSelected);
const inputHandler = jasmine.createSpy('inputHandler');
root.addEventListener('input', inputHandler);
const a3 = harnesses[2];
await a3.clickWithMouse();
expect(a3.element.checked)
.withContext('clicked radio checked')
.toBeTrue();
expect(inputHandler).toHaveBeenCalledTimes(1);
expect(inputHandler).toHaveBeenCalledWith(jasmine.any(InputEvent));
});
});
describe('navigation', () => {