From d465d2bc0b564e5b4580a66782125aa9a7357e02 Mon Sep 17 00:00:00 2001 From: Boris Diakur Date: Tue, 16 Nov 2021 22:45:55 +0100 Subject: [PATCH] fix(ld-radio): emits input event on click from outside --- src/liquid/components/ld-radio/ld-radio.tsx | 8 ++++++++ .../components/ld-radio/test/ld-radio.spec.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/liquid/components/ld-radio/ld-radio.tsx b/src/liquid/components/ld-radio/ld-radio.tsx index ef1626977e..77fccb162b 100644 --- a/src/liquid/components/ld-radio/ld-radio.tsx +++ b/src/liquid/components/ld-radio/ld-radio.tsx @@ -120,6 +120,14 @@ export class LdRadio implements InnerFocusable { } this.checked = true + + if (!ev.isTrusted) { + // This happens, when a click event is dispatched on the host element + // from the outside i.e. on click on a parent ld-label element. + this.el.dispatchEvent( + new Event('input', { bubbles: true, composed: true }) + ) + } } private focusAndSelect(dir: 'next' | 'prev') { diff --git a/src/liquid/components/ld-radio/test/ld-radio.spec.ts b/src/liquid/components/ld-radio/test/ld-radio.spec.ts index f5f9794a4f..f40868b088 100644 --- a/src/liquid/components/ld-radio/test/ld-radio.spec.ts +++ b/src/liquid/components/ld-radio/test/ld-radio.spec.ts @@ -90,6 +90,20 @@ describe('ld-radio', () => { expect(spyBlur).toHaveBeenCalled() }) + it('emits input event on click', async () => { + const page = await newSpecPage({ + components: [LdRadio], + html: ``, + }) + const ldRadio = page.root + + const spyInput = jest.fn() + ldRadio.addEventListener('input', spyInput) + ldRadio.click() + + expect(spyInput).toHaveBeenCalled() + }) + it('allows to set inner focus', async () => { const page = await newSpecPage({ components: [LdRadio],