Skip to content

Commit 5b1a1d5

Browse files
committed
Change check so it works for other elements inside the label.
1 parent 20a9a3a commit 5b1a1d5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,14 @@ function shouldCommit(details: Element, event: Event) {
172172
const menuitem = target.closest('[role="menuitem"], [role="menuitemradio"]')
173173
if (!menuitem) return
174174

175+
const input = menuitem.querySelector('input')
176+
175177
// Ignore double event caused by inputs nested in labels
176-
if (menuitem.tagName === 'LABEL' && target !== menuitem) return
178+
// Known issue: This will wrongly ignore a legit click event on an already checked input,
179+
// but inputs are not expected to be visible in the menu items.
180+
// I've found no way to discriminate the legit event from the echo one, and we don't want to trigger the selected event twice.
181+
if (menuitem.tagName === 'LABEL' && target === input) return
177182

178-
const input = menuitem.querySelector('input')
179183
// An input inside a label will be committed as a change event (we assume it's a radio input),
180184
// unless the input is already checked, so we need to commit on click (to close the popup)
181185
const onlyCommitOnChangeEvent = menuitem.tagName === 'LABEL' && input && !input.checked

0 commit comments

Comments
 (0)