1- import { kebabCase } from './helpers'
1+ import { kebabCase , hasClassInTree } from './helpers'
22import { Optgroup , Option } from './store'
33
44export default class Select {
@@ -167,7 +167,7 @@ export default class Select {
167167 let classChanged = false
168168 let disabledChanged = false
169169 let optgroupOptionChanged = false
170- let selectionChanged = false ;
170+ let selectionChanged = false
171171
172172 // Loop through mutations and check various things
173173 for ( const m of mutations ) {
@@ -187,7 +187,7 @@ export default class Select {
187187 for ( const n of Array . from ( m . addedNodes ) ) {
188188 if ( n . nodeName === 'OPTION' && ( < HTMLOptionElement > n ) . value === this . select . value ) {
189189 // we added a new option that's now the select value
190- selectionChanged = true ;
190+ selectionChanged = true
191191 break
192192 }
193193 }
@@ -228,7 +228,7 @@ export default class Select {
228228 this . pendingOptionsChange = currentData
229229 }
230230 }
231- if ( selectionChanged ) {
231+ if ( selectionChanged ) {
232232 this . select . dispatchEvent ( new Event ( 'change' ) )
233233 }
234234 return
@@ -239,7 +239,7 @@ export default class Select {
239239 this . changeListen ( true )
240240 }
241241
242- if ( selectionChanged ) {
242+ if ( selectionChanged ) {
243243 this . select . dispatchEvent ( new Event ( 'change' ) )
244244 }
245245 }
@@ -566,14 +566,18 @@ export default class Select {
566566 const labelClickHandler = ( e : MouseEvent ) => {
567567 const target = e . target as HTMLElement
568568
569+ // Check if click is on SlimSelect UI elements (main div or content)
570+ const isSlimSelectElement = hasClassInTree ( target , this . select . dataset . id ! )
571+
569572 // Prevent default label behavior (focusing the select)
570573 // This needs to happen for all clicks on the label or its children
571574 // to prevent the browser from focusing the hidden select
572575 e . preventDefault ( )
573576 // e.stopPropagation() // dont stop propagation
574577
575- // Only handle the click if it's directly on the label
576- if ( target === label && this . onLabelClick ) {
578+ // Only trigger the toggle if the click is NOT on SlimSelect elements
579+ // This allows clicking label text/children to toggle, while wrapped SlimSelect handles its own clicks
580+ if ( ! isSlimSelectElement && this . onLabelClick ) {
577581 this . onLabelClick ( )
578582 }
579583 }
0 commit comments