@smilodon/core 1.11.0 → 1.11.1

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.
package/README.md CHANGED
@@ -334,6 +334,16 @@ select.optionRenderer = (item, index) => {
334
334
 
335
335
  `optionRenderer` is the maintained `EnhancedSelect` API. The legacy `NativeSelectElement` has a separate compatibility surface; do not copy its `optionTemplate` examples into `enhanced-select` integrations.
336
336
 
337
+ ### Active state on custom option roots
338
+
339
+ For custom-rendered options, `classMap.active` names the class or classes applied to the active option root. Core removes its built-in active aliases and previously configured active classes when another option becomes active, when the option is rendered again, or when `classMap` changes. The active `data-sm-state` token is reconciled with those classes, so an inactive option does not retain stale active styling.
340
+
341
+ ```typescript
342
+ select.classMap = { active: 'is-active keyboard-focus' };
343
+ ```
344
+
345
+ Style the returned option root using the configured class. If the active class map changes, Core removes classes from the prior map before applying the current active state.
346
+
337
347
  ---
338
348
 
339
349
  ### Events
package/dist/index.cjs CHANGED
@@ -4117,6 +4117,7 @@ class EnhancedSelect extends HTMLElement {
4117
4117
  this._pendingSearchRenderMark = false;
4118
4118
  this._rangeAnchorIndex = null;
4119
4119
  this._customOptionBoundElements = new WeakSet();
4120
+ this._customOptionManagedActiveClasses = new WeakMap();
4120
4121
  this._customOptionNormalizedIds = new WeakMap();
4121
4122
  this._customOptionNormalizedLabels = new WeakMap();
4122
4123
  this._mirrorGlobalStylesForCustomOptions = false;
@@ -7793,8 +7794,7 @@ class EnhancedSelect extends HTMLElement {
7793
7794
  prevOption.setActive(false);
7794
7795
  }
7795
7796
  else {
7796
- // Lightweight option - remove active class
7797
- prevOption.classList.remove('active', 'smilodon-option--active');
7797
+ this._syncCustomOptionActiveClasses(prevOption, false);
7798
7798
  }
7799
7799
  }
7800
7800
  }
@@ -7805,8 +7805,7 @@ class EnhancedSelect extends HTMLElement {
7805
7805
  option.setActive(true);
7806
7806
  }
7807
7807
  else {
7808
- // Lightweight option - add active class
7809
- option.classList.add('active', 'smilodon-option--active');
7808
+ this._syncCustomOptionActiveClasses(option, true);
7810
7809
  }
7811
7810
  if (typeof option.scrollIntoView === 'function') {
7812
7811
  // Don't scroll wildly when just opening with pre-selections
@@ -10301,6 +10300,26 @@ class EnhancedSelect extends HTMLElement {
10301
10300
  option.ensureRendered();
10302
10301
  }
10303
10302
  }
10303
+ /** Keep custom option active classes aligned with the engine, including previous class maps. */
10304
+ _syncCustomOptionActiveClasses(option, active) {
10305
+ const mapped = (this.classMap?.active ?? 'active sm-active').split(/\s+/).filter(Boolean);
10306
+ const styled = (this._config.styles.classNames?.activeOption ?? '').split(/\s+/).filter(Boolean);
10307
+ const current = [...new Set([...mapped, ...styled, 'smilodon-option--active'])];
10308
+ const previous = this._customOptionManagedActiveClasses.get(option) ?? [];
10309
+ option.classList.remove(...new Set([...previous, ...current, 'active', 'sm-active', 'smilodon-option--active']));
10310
+ if (active)
10311
+ option.classList.add(...current);
10312
+ this._customOptionManagedActiveClasses.set(option, current);
10313
+ const states = new Set((option.dataset.smState ?? '').split(/\s+/).filter(Boolean));
10314
+ if (active)
10315
+ states.add('active');
10316
+ else
10317
+ states.delete('active');
10318
+ if (states.size)
10319
+ option.dataset.smState = [...states].join(' ');
10320
+ else
10321
+ delete option.dataset.smState;
10322
+ }
10304
10323
  _normalizeCustomOptionElement(element, meta) {
10305
10324
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
10306
10325
  // Add part attribute for styling
@@ -10322,7 +10341,6 @@ class EnhancedSelect extends HTMLElement {
10322
10341
  const isDisabledInteractive = isDisabled && (isDisabledSelectable || isDisabledHoverable);
10323
10342
  // Resolve classes from classMap or defaults
10324
10343
  const selectedClasses = (this.classMap?.selected ?? 'selected sm-selected').split(' ').filter(Boolean);
10325
- const activeClasses = (this.classMap?.active ?? 'active sm-active').split(' ').filter(Boolean);
10326
10344
  const disabledClasses = (this.classMap?.disabled ?? 'disabled sm-disabled').split(' ').filter(Boolean);
10327
10345
  if (isSelected) {
10328
10346
  optionEl.classList.add(...selectedClasses);
@@ -10338,20 +10356,7 @@ class EnhancedSelect extends HTMLElement {
10338
10356
  optionEl.classList.remove(...this._config.styles.classNames.selectedOption.split(' ').filter(Boolean));
10339
10357
  }
10340
10358
  }
10341
- if (isActive) {
10342
- optionEl.classList.add(...activeClasses);
10343
- optionEl.classList.add('smilodon-option--active');
10344
- if (this._config.styles.classNames?.activeOption) {
10345
- optionEl.classList.add(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10346
- }
10347
- }
10348
- else {
10349
- optionEl.classList.remove(...activeClasses);
10350
- optionEl.classList.remove('smilodon-option--active');
10351
- if (this._config.styles.classNames?.activeOption) {
10352
- optionEl.classList.remove(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10353
- }
10354
- }
10359
+ this._syncCustomOptionActiveClasses(optionEl, isActive);
10355
10360
  if (isDisabled) {
10356
10361
  optionEl.classList.add(...disabledClasses);
10357
10362
  optionEl.classList.add('smilodon-option--disabled');