slim-select 3.1.4 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { kebabCase } from './helpers'
1
+ import { kebabCase, hasClassInTree } from './helpers'
2
2
  import { Optgroup, Option } from './store'
3
3
 
4
4
  export default class Select {
@@ -167,6 +167,7 @@ export default class Select {
167
167
  let classChanged = false
168
168
  let disabledChanged = false
169
169
  let optgroupOptionChanged = false
170
+ let selectionChanged = false
170
171
 
171
172
  // Loop through mutations and check various things
172
173
  for (const m of mutations) {
@@ -186,7 +187,7 @@ export default class Select {
186
187
  for (const n of Array.from(m.addedNodes)) {
187
188
  if (n.nodeName === 'OPTION' && (<HTMLOptionElement>n).value === this.select.value) {
188
189
  // we added a new option that's now the select value
189
- this.select.dispatchEvent(new Event('change'))
190
+ selectionChanged = true
190
191
  break
191
192
  }
192
193
  }
@@ -227,6 +228,9 @@ export default class Select {
227
228
  this.pendingOptionsChange = currentData
228
229
  }
229
230
  }
231
+ if (selectionChanged) {
232
+ this.select.dispatchEvent(new Event('change'))
233
+ }
230
234
  return
231
235
  }
232
236
 
@@ -234,6 +238,10 @@ export default class Select {
234
238
  this.onOptionsChange(this.getData())
235
239
  this.changeListen(true)
236
240
  }
241
+
242
+ if (selectionChanged) {
243
+ this.select.dispatchEvent(new Event('change'))
244
+ }
237
245
  }
238
246
 
239
247
  // From the select element pull optgroup and options into data
@@ -558,20 +566,19 @@ export default class Select {
558
566
  const labelClickHandler = (e: MouseEvent) => {
559
567
  const target = e.target as HTMLElement
560
568
 
561
- // Only continue if the target is the label
562
- if (target !== label) {
563
- return
564
- }
569
+ // Check if click is on SlimSelect UI elements (main div or content)
570
+ const isSlimSelectElement = hasClassInTree(target, this.select.dataset.id!)
565
571
 
566
- // At this point, we know the click is directly on the label element
567
572
  // Prevent default label behavior (focusing the select)
568
- // Don't stop propagation to allow other handlers (like closing other SlimSelect instances)
573
+ // This needs to happen for all clicks on the label or its children
574
+ // to prevent the browser from focusing the hidden select
569
575
  e.preventDefault()
570
576
  // e.stopPropagation() // dont stop propagation
571
577
 
572
- // Trigger the callback to toggle SlimSelect
573
- if (this.onLabelClick) {
574
- 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) {
581
+ this.onLabelClick()
575
582
  }
576
583
  }
577
584
 
@@ -17,6 +17,7 @@ const defaultSettings: { [key: string]: any } = {
17
17
  alwaysOpen: false,
18
18
  showSearch: true,
19
19
  focusSearch: true,
20
+ keepSearch: false,
20
21
  ariaLabel: 'Combobox',
21
22
  searchPlaceholder: 'Search...',
22
23
  searchText: 'No Results',
@@ -16,6 +16,7 @@ export default class Settings {
16
16
  public alwaysOpen: boolean
17
17
  public showSearch: boolean
18
18
  public focusSearch: boolean
19
+ public keepSearch: boolean
19
20
  public ariaLabel: string
20
21
  public searchPlaceholder: string
21
22
  public searchText: string
@@ -50,6 +51,7 @@ export default class Settings {
50
51
  this.alwaysOpen = settings.alwaysOpen !== undefined ? settings.alwaysOpen : false
51
52
  this.showSearch = settings.showSearch !== undefined ? settings.showSearch : true
52
53
  this.focusSearch = settings.focusSearch !== undefined ? settings.focusSearch : true
54
+ this.keepSearch = settings.keepSearch !== undefined ? settings.keepSearch : false
53
55
  this.ariaLabel = settings.ariaLabel || 'Combobox'
54
56
  this.searchPlaceholder = settings.searchPlaceholder || 'Search...'
55
57
  this.searchText = settings.searchText || 'No Results'
@@ -362,6 +362,11 @@
362
362
  }
363
363
  }
364
364
 
365
+ &.ss-dir-above .ss-search {
366
+ border-bottom: none;
367
+ border-top: 1px solid var(--ss-border-color);
368
+ }
369
+
365
370
  .ss-list {
366
371
  flex: 1 1 auto;
367
372
  height: auto;