@smilodon/core 1.10.2 → 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
@@ -154,6 +154,22 @@ select.addEventListener('change', (event) => {
154
154
  });
155
155
  ```
156
156
 
157
+ ### Hover stability
158
+
159
+ Option hover styling no longer moves the option hit target or introduces a layout-changing border. Hover border tokens render as outlines; hover-specific border-bottom and transform styling is not applied to the selectable option. The former `styles.hoverOption.transform` setting no longer moves the selectable element on hover; animate inner content instead if motion is needed. Option selection and keyboard-active styling remain separate from hover.
160
+
161
+ ### Custom arrow slot
162
+
163
+ The default chevron remains in place unless a light-DOM child is assigned to the `arrow` slot:
164
+
165
+ ```html
166
+ <enhanced-select id="my-select">
167
+ <span slot="arrow" aria-hidden="true">▼</span>
168
+ </enhanced-select>
169
+ ```
170
+
171
+ The custom node is decorative and Core keeps ownership of the arrow click behavior. The built-in arrow rotates with the popup; a custom node does not rotate unless the consumer styles it using the host's `data-open="true"` state. Core does not impose its arrow color or hover background on assigned custom content.
172
+
157
173
  ### Framework Usage
158
174
 
159
175
  **In browser DOM frameworks, `@smilodon/core` can be used directly** as a Web Component; framework adapters are available for framework-specific APIs.
@@ -318,6 +334,16 @@ select.optionRenderer = (item, index) => {
318
334
 
319
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.
320
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
+
321
347
  ---
322
348
 
323
349
  ### Events
@@ -528,6 +554,8 @@ The component implements keyboard interaction paths including:
528
554
  | `Ctrl+A` (multi-select) | Select all options |
529
555
  | Type characters | Type-ahead search |
530
556
 
557
+ When an empty single-select opens, it has no active option and does not expose `aria-activedescendant` until keyboard navigation begins. Press `ArrowDown` to activate the first selectable option. If a value is already selected, opening the list activates that selected option.
558
+
531
559
  **Multi-Select Range Selection:**
532
560
  - `Shift + ↑/↓` - Range selection
533
561
  - `Ctrl/Cmd + Click` - Toggle individual items
package/dist/index.cjs CHANGED
@@ -2606,14 +2606,13 @@ class SelectOption extends HTMLElement {
2606
2606
  transition: var(--select-option-transition, background-color 0.2s ease);
2607
2607
  }
2608
2608
 
2609
- :host(:hover):not(.smilodon-option--disabled):not([aria-disabled="true"]),
2609
+ :host(:hover:not(.smilodon-option--disabled):not([aria-disabled="true"])),
2610
2610
  :host(.smilodon-option--disabled-hoverable:hover) {
2611
2611
  background: var(--select-option-hover-bg, #f0f0f0);
2612
2612
  color: var(--select-option-hover-color, var(--select-option-color, var(--select-text-color, #1f2937)));
2613
- border: var(--select-option-hover-border, var(--select-option-border, none));
2614
- border-bottom: var(--select-option-hover-border-bottom, var(--select-option-border-bottom, none));
2613
+ outline: var(--select-option-hover-border, none);
2614
+ outline-offset: -1px;
2615
2615
  box-shadow: var(--select-option-hover-shadow, var(--select-option-shadow, none));
2616
- transform: var(--select-option-hover-transform, var(--select-option-transform, none));
2617
2616
  }
2618
2617
 
2619
2618
  /* Keep the visual surface on the host so external utility classes applied
@@ -2634,10 +2633,9 @@ class SelectOption extends HTMLElement {
2634
2633
  :host(.smilodon-option--selected:hover) {
2635
2634
  background: var(--select-option-selected-hover-bg, var(--select-option-selected-bg, #e3f2fd));
2636
2635
  color: var(--select-option-selected-hover-color, var(--select-option-selected-color, #1976d2));
2637
- border: var(--select-option-selected-hover-border, var(--select-option-selected-border, var(--select-option-border, none)));
2638
- border-bottom: var(--select-option-selected-hover-border-bottom, var(--select-option-selected-border-bottom, var(--select-option-border-bottom, none)));
2636
+ outline: var(--select-option-selected-hover-border, var(--select-option-hover-border, none));
2637
+ outline-offset: -1px;
2639
2638
  box-shadow: var(--select-option-selected-hover-shadow, var(--select-option-selected-shadow, var(--select-option-shadow, none)));
2640
- transform: var(--select-option-selected-hover-transform, var(--select-option-selected-transform, var(--select-option-transform, none)));
2641
2639
  }
2642
2640
 
2643
2641
  :host(.smilodon-option--active):not(.smilodon-option--disabled):not([aria-disabled="true"]),
@@ -4119,6 +4117,7 @@ class EnhancedSelect extends HTMLElement {
4119
4117
  this._pendingSearchRenderMark = false;
4120
4118
  this._rangeAnchorIndex = null;
4121
4119
  this._customOptionBoundElements = new WeakSet();
4120
+ this._customOptionManagedActiveClasses = new WeakMap();
4122
4121
  this._customOptionNormalizedIds = new WeakMap();
4123
4122
  this._customOptionNormalizedLabels = new WeakMap();
4124
4123
  this._mirrorGlobalStylesForCustomOptions = false;
@@ -5494,10 +5493,21 @@ class EnhancedSelect extends HTMLElement {
5494
5493
  const container = document.createElement('div');
5495
5494
  container.className = 'dropdown-arrow-container';
5496
5495
  container.innerHTML = `
5497
- <svg class="dropdown-arrow" part="arrow" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
5498
- <path d="M4 6L8 10L12 6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
5499
- </svg>
5496
+ <slot name="arrow">
5497
+ <svg class="dropdown-arrow" part="arrow" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
5498
+ <path d="M4 6L8 10L12 6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
5499
+ </svg>
5500
+ </slot>
5500
5501
  `;
5502
+ const slot = container.querySelector('slot[name="arrow"]');
5503
+ slot?.addEventListener('slotchange', () => {
5504
+ if (slot.assignedElements({ flatten: true }).length > 0) {
5505
+ this.setAttribute('data-custom-arrow', 'true');
5506
+ }
5507
+ else {
5508
+ this.removeAttribute('data-custom-arrow');
5509
+ }
5510
+ });
5501
5511
  return container;
5502
5512
  }
5503
5513
  _createClearControl() {
@@ -5653,7 +5663,7 @@ class EnhancedSelect extends HTMLElement {
5653
5663
  --select-scrollbar-width: 6px;
5654
5664
  --select-scrollbar-thumb-radius: 3px;
5655
5665
  --select-option-hover-enabled: 1;
5656
- --select-option-hover-transform: translateX(2px);
5666
+ --select-option-hover-transform: none;
5657
5667
  --select-option-font-weight: 450;
5658
5668
  --select-option-margin: 2px 0;
5659
5669
  --select-input-font-size: inherit;
@@ -6212,6 +6222,10 @@ class EnhancedSelect extends HTMLElement {
6212
6222
  .dropdown-arrow-container:hover {
6213
6223
  background-color: var(--select-arrow-hover-bg, rgba(15, 52, 96, 0.05));
6214
6224
  }
6225
+
6226
+ :host([data-custom-arrow="true"]) .dropdown-arrow-container:hover {
6227
+ background-color: transparent;
6228
+ }
6215
6229
 
6216
6230
  .dropdown-arrow {
6217
6231
  width: var(--select-arrow-width, var(--select-arrow-size, 16px));
@@ -6433,8 +6447,7 @@ class EnhancedSelect extends HTMLElement {
6433
6447
  transition: var(--select-option-transition,
6434
6448
  background var(--select-transition-fast),
6435
6449
  color var(--select-transition-fast),
6436
- border var(--select-transition-fast),
6437
- transform var(--select-transition-fast),
6450
+ outline-color var(--select-transition-fast),
6438
6451
  box-shadow var(--select-transition-fast)
6439
6452
  );
6440
6453
  user-select: none;
@@ -6448,9 +6461,10 @@ class EnhancedSelect extends HTMLElement {
6448
6461
  .option:hover:not(.disabled):not(.smilodon-option--disabled),
6449
6462
  .option.smilodon-option--disabled-hoverable:hover {
6450
6463
  background: var(--select-option-hover-bg, var(--select-surface-elevated));
6451
- border: var(--select-option-hover-border, var(--select-option-border, none));
6464
+ /* Hover decoration must not resize or translate the pointer hit target. */
6465
+ outline: var(--select-option-hover-border, none);
6466
+ outline-offset: -1px;
6452
6467
  color: var(--select-option-hover-color, var(--select-text));
6453
- transform: var(--select-option-hover-transform, none);
6454
6468
  }
6455
6469
 
6456
6470
  .option.selected {
@@ -6493,7 +6507,8 @@ class EnhancedSelect extends HTMLElement {
6493
6507
 
6494
6508
  .option.selected:hover {
6495
6509
  background: var(--select-option-selected-hover-bg, var(--select-option-selected-bg, linear-gradient(135deg, rgba(15, 52, 96, 0.12) 0%, rgba(15, 52, 96, 0.06) 100%)));
6496
- border: var(--select-option-selected-hover-border, var(--select-option-selected-border, var(--select-option-hover-border, var(--select-option-border, none))));
6510
+ outline: var(--select-option-selected-hover-border, var(--select-option-hover-border, none));
6511
+ outline-offset: -1px;
6497
6512
  color: var(--select-option-selected-hover-color, var(--select-option-selected-color, var(--select-accent)));
6498
6513
  }
6499
6514
 
@@ -7779,8 +7794,7 @@ class EnhancedSelect extends HTMLElement {
7779
7794
  prevOption.setActive(false);
7780
7795
  }
7781
7796
  else {
7782
- // Lightweight option - remove active class
7783
- prevOption.classList.remove('active', 'smilodon-option--active');
7797
+ this._syncCustomOptionActiveClasses(prevOption, false);
7784
7798
  }
7785
7799
  }
7786
7800
  }
@@ -7791,8 +7805,7 @@ class EnhancedSelect extends HTMLElement {
7791
7805
  option.setActive(true);
7792
7806
  }
7793
7807
  else {
7794
- // Lightweight option - add active class
7795
- option.classList.add('active', 'smilodon-option--active');
7808
+ this._syncCustomOptionActiveClasses(option, true);
7796
7809
  }
7797
7810
  if (typeof option.scrollIntoView === 'function') {
7798
7811
  // Don't scroll wildly when just opening with pre-selections
@@ -7923,7 +7936,9 @@ class EnhancedSelect extends HTMLElement {
7923
7936
  _setInitialActiveOption() {
7924
7937
  const selectableIndices = this._getSelectableOptionIndices();
7925
7938
  const selected = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
7926
- if (selectableIndices.length === 0 || (this._config.selection.mode === 'multi' && selected.length === 0)) {
7939
+ // Opening an empty select must not implicitly assign an active descendant.
7940
+ // Keyboard navigation and pointer interaction establish active identity.
7941
+ if (selectableIndices.length === 0 || selected.length === 0) {
7927
7942
  this._dispatchActiveKey(null, 'open', 'initial active option');
7928
7943
  return;
7929
7944
  }
@@ -10285,6 +10300,26 @@ class EnhancedSelect extends HTMLElement {
10285
10300
  option.ensureRendered();
10286
10301
  }
10287
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
+ }
10288
10323
  _normalizeCustomOptionElement(element, meta) {
10289
10324
  const optionEl = element instanceof HTMLElement ? element : document.createElement('div');
10290
10325
  // Add part attribute for styling
@@ -10306,7 +10341,6 @@ class EnhancedSelect extends HTMLElement {
10306
10341
  const isDisabledInteractive = isDisabled && (isDisabledSelectable || isDisabledHoverable);
10307
10342
  // Resolve classes from classMap or defaults
10308
10343
  const selectedClasses = (this.classMap?.selected ?? 'selected sm-selected').split(' ').filter(Boolean);
10309
- const activeClasses = (this.classMap?.active ?? 'active sm-active').split(' ').filter(Boolean);
10310
10344
  const disabledClasses = (this.classMap?.disabled ?? 'disabled sm-disabled').split(' ').filter(Boolean);
10311
10345
  if (isSelected) {
10312
10346
  optionEl.classList.add(...selectedClasses);
@@ -10322,20 +10356,7 @@ class EnhancedSelect extends HTMLElement {
10322
10356
  optionEl.classList.remove(...this._config.styles.classNames.selectedOption.split(' ').filter(Boolean));
10323
10357
  }
10324
10358
  }
10325
- if (isActive) {
10326
- optionEl.classList.add(...activeClasses);
10327
- optionEl.classList.add('smilodon-option--active');
10328
- if (this._config.styles.classNames?.activeOption) {
10329
- optionEl.classList.add(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10330
- }
10331
- }
10332
- else {
10333
- optionEl.classList.remove(...activeClasses);
10334
- optionEl.classList.remove('smilodon-option--active');
10335
- if (this._config.styles.classNames?.activeOption) {
10336
- optionEl.classList.remove(...this._config.styles.classNames.activeOption.split(' ').filter(Boolean));
10337
- }
10338
- }
10359
+ this._syncCustomOptionActiveClasses(optionEl, isActive);
10339
10360
  if (isDisabled) {
10340
10361
  optionEl.classList.add(...disabledClasses);
10341
10362
  optionEl.classList.add('smilodon-option--disabled');