Skip to content

Commit a19743b

Browse files
authored
Merge pull request #655 from AnthonyANI/label-click-event-fix
select label - prevent default click for children
2 parents a46c61a + 3cdb8c9 commit a19743b

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/slim-select/select.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,20 +566,15 @@ export default class Select {
566566
const labelClickHandler = (e: MouseEvent) => {
567567
const target = e.target as HTMLElement
568568

569-
// Only continue if the target is the label
570-
if (target !== label) {
571-
return
572-
}
573-
574-
// At this point, we know the click is directly on the label element
575569
// Prevent default label behavior (focusing the select)
576-
// Don't stop propagation to allow other handlers (like closing other SlimSelect instances)
570+
// This needs to happen for all clicks on the label or its children
571+
// to prevent the browser from focusing the hidden select
577572
e.preventDefault()
578573
// e.stopPropagation() // dont stop propagation
579574

580-
// Trigger the callback to toggle SlimSelect
581-
if (this.onLabelClick) {
582-
this.onLabelClick!()
575+
// Only handle the click if it's directly on the label
576+
if (target === label && this.onLabelClick) {
577+
this.onLabelClick()
583578
}
584579
}
585580

0 commit comments

Comments
 (0)