From e444de3c0264697e2fc094c35ae59808a04ff29f Mon Sep 17 00:00:00 2001 From: Elizabeth Mitchell Date: Thu, 14 Sep 2023 17:25:19 -0700 Subject: [PATCH] fix(radio): dispatches input event on select PiperOrigin-RevId: 565522665 --- radio/internal/radio.ts | 2 ++ radio/radio_test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/radio/internal/radio.ts b/radio/internal/radio.ts index 3a85bd5ad7..237da470da 100644 --- a/radio/internal/radio.ts +++ b/radio/internal/radio.ts @@ -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) { diff --git a/radio/radio_test.ts b/radio/radio_test.ts index e6865957b3..2b2a4da664 100644 --- a/radio/radio_test.ts +++ b/radio/radio_test.ts @@ -139,6 +139,21 @@ describe('', () => { 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', () => {