Skip to content

Commit

Permalink
fix(ld-radio): emits input event on click from outside
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Nov 16, 2021
1 parent cad4501 commit d465d2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/liquid/components/ld-radio/ld-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
14 changes: 14 additions & 0 deletions src/liquid/components/ld-radio/test/ld-radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ describe('ld-radio', () => {
expect(spyBlur).toHaveBeenCalled()
})

it('emits input event on click', async () => {
const page = await newSpecPage({
components: [LdRadio],
html: `<ld-radio />`,
})
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],
Expand Down

0 comments on commit d465d2b

Please sign in to comment.