slim-select 3.1.3 → 3.2.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.
@@ -157,10 +157,28 @@ export default class Render {
157
157
  this.main.main.removeAttribute('aria-activedescendant')
158
158
 
159
159
  // Remove direction class from main and content after animation is complete
160
+ const animationTiming = this.getAnimationTiming()
160
161
  setTimeout(() => {
161
162
  this.main.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow)
162
163
  this.content.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow)
163
- }, 100)
164
+ }, animationTiming)
165
+ }
166
+
167
+ private getAnimationTiming(): number {
168
+ const computedStyle = getComputedStyle(this.content.main)
169
+ const cssValue = computedStyle.getPropertyValue('--ss-animation-timing').trim()
170
+
171
+ if (cssValue) {
172
+ // Parse CSS time value (e.g., "0.2s" or "200ms")
173
+ if (cssValue.endsWith('ms')) {
174
+ return parseFloat(cssValue)
175
+ } else if (cssValue.endsWith('s')) {
176
+ return parseFloat(cssValue) * 1000
177
+ }
178
+ }
179
+
180
+ // Fall back to default 200ms
181
+ return 200
164
182
  }
165
183
 
166
184
  public updateClassStyles(): void {
@@ -881,7 +899,7 @@ export default class Render {
881
899
  }
882
900
 
883
901
  public searchFocus(): void {
884
- this.content.search.input.focus()
902
+ this.content.search.input.focus({ preventScroll: true })
885
903
  }
886
904
 
887
905
  public getOptions(notPlaceholder = false, notDisabled = false, notHidden = false): HTMLDivElement[] {
@@ -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
@@ -556,17 +564,17 @@ export default class Select {
556
564
 
557
565
  // Add click handler to label
558
566
  const labelClickHandler = (e: MouseEvent) => {
567
+ const target = e.target as HTMLElement
568
+
559
569
  // Prevent default label behavior (focusing the select)
570
+ // This needs to happen for all clicks on the label or its children
571
+ // to prevent the browser from focusing the hidden select
560
572
  e.preventDefault()
561
- e.stopPropagation()
573
+ // e.stopPropagation() // dont stop propagation
562
574
 
563
- // Trigger the callback to open SlimSelect
564
- if (this.onLabelClick) {
565
- // Use setTimeout to ensure this happens after any browser-initiated events
566
- // are prevented by our prevent handlers
567
- setTimeout(() => {
568
- this.onLabelClick!()
569
- }, 0)
575
+ // Only handle the click if it's directly on the label
576
+ if (target === label && this.onLabelClick) {
577
+ this.onLabelClick()
570
578
  }
571
579
  }
572
580
 
@@ -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'