@smilodon/core 1.20.0 → 1.22.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.
package/dist/index.cjs CHANGED
@@ -2940,6 +2940,15 @@ class SelectOption extends HTMLElement {
2940
2940
  pointer-events: none;
2941
2941
  }
2942
2942
 
2943
+ .remove-button-icon > [data-smilodon-fallback-icon],
2944
+ .remove-button-icon > [data-smilodon-react-icon-root] {
2945
+ display: contents;
2946
+ }
2947
+
2948
+ .remove-button-icon[data-smilodon-icon-owner="react"] > [data-smilodon-fallback-icon] {
2949
+ display: none;
2950
+ }
2951
+
2943
2952
  .remove-button-icon svg {
2944
2953
  width: 100%;
2945
2954
  height: 100%;
@@ -3062,15 +3071,20 @@ class SelectOption extends HTMLElement {
3062
3071
  const removeIcon = document.createElement('span');
3063
3072
  removeIcon.className = 'remove-button-icon';
3064
3073
  removeIcon.setAttribute('part', 'chip-remove-icon');
3074
+ const fallbackIcon = document.createElement('span');
3075
+ fallbackIcon.setAttribute('data-smilodon-fallback-icon', '');
3076
+ const portalRoot = document.createElement('span');
3077
+ portalRoot.setAttribute('data-smilodon-react-icon-root', '');
3065
3078
  const iconMarkup = this._config.removeButtonIcon && this._config.removeButtonIcon.trim()
3066
3079
  ? this._config.removeButtonIcon
3067
3080
  : '×';
3068
3081
  if (iconMarkup.trim().startsWith('<')) {
3069
- removeIcon.innerHTML = iconMarkup;
3082
+ fallbackIcon.innerHTML = iconMarkup;
3070
3083
  }
3071
3084
  else {
3072
- removeIcon.textContent = iconMarkup;
3085
+ fallbackIcon.textContent = iconMarkup;
3073
3086
  }
3087
+ removeIcon.append(fallbackIcon, portalRoot);
3074
3088
  this._removeButton.appendChild(removeIcon);
3075
3089
  this._container.appendChild(this._removeButton);
3076
3090
  }
@@ -4445,6 +4459,15 @@ class EnhancedSelect extends HTMLElement {
4445
4459
  super();
4446
4460
  this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
4447
4461
  this._hasLastInvalidDataLoadingCandidate = false;
4462
+ this._selectedLabelTooltipTrigger = null;
4463
+ this._selectedLabelTooltipPointerTrigger = null;
4464
+ this._selectedLabelTooltipFocusTrigger = null;
4465
+ this._selectedLabelTooltipPointerInside = false;
4466
+ this._selectedLabelTooltipDismissedTrigger = null;
4467
+ this._selectedLabelTooltipHideTimer = null;
4468
+ this._selectedLabelTooltipResizeObserver = null;
4469
+ this._selectedLabelTooltipMeasureFrame = null;
4470
+ this._selectedLabelKeys = new WeakMap();
4448
4471
  this._busyPresentationVisible = false;
4449
4472
  this._busyPresentationStartedAt = null;
4450
4473
  this._busyPresentationGeneration = 0;
@@ -4544,6 +4567,9 @@ class EnhancedSelect extends HTMLElement {
4544
4567
  this._rangeAnchorKey = null;
4545
4568
  /** Chip identity is tracked independently of dropdown option positions. */
4546
4569
  this._lastRenderedChipKeys = null;
4570
+ /** Stable presentation nodes keyed by the engine's selected-item identity. */
4571
+ this._chipElements = new Map();
4572
+ this._chipExitStates = new Map();
4547
4573
  this._latestChipScrollGeneration = 0;
4548
4574
  this._latestChipScrollFrame = null;
4549
4575
  this._customOptionBoundElements = new WeakSet();
@@ -4629,6 +4655,14 @@ class EnhancedSelect extends HTMLElement {
4629
4655
  this._handleClose('outside-pointer');
4630
4656
  }
4631
4657
  };
4658
+ this._scheduleSelectedLabelTooltipMeasure = () => {
4659
+ if (this._selectedLabelTooltipMeasureFrame !== null || !this.isConnected)
4660
+ return;
4661
+ this._selectedLabelTooltipMeasureFrame = this._requestLifecycleFrame(() => {
4662
+ this._selectedLabelTooltipMeasureFrame = null;
4663
+ this._refreshSelectedLabelTooltipMeasurements();
4664
+ });
4665
+ };
4632
4666
  this._shadow = this.attachShadow({ mode: 'open' });
4633
4667
  this._uniqueId = `enhanced-select-${Math.random().toString(36).substr(2, 9)}`;
4634
4668
  this._rendererHelpers = this._buildRendererHelpers();
@@ -4663,6 +4697,8 @@ class EnhancedSelect extends HTMLElement {
4663
4697
  this._inputContainer = this._createInputContainer();
4664
4698
  this._inputContent = this._createInputContent();
4665
4699
  this._input = this._createInput();
4700
+ this._selectedLabelTooltip = this._createSelectedLabelTooltip();
4701
+ this._selectedLabelTooltipTextMeasure = this._createSelectedLabelTooltipTextMeasure();
4666
4702
  this._arrowContainer = this._createArrowContainer();
4667
4703
  this._clearControl = this._createClearControl();
4668
4704
  this._dropdown = this._createDropdown();
@@ -4682,15 +4718,29 @@ class EnhancedSelect extends HTMLElement {
4682
4718
  }
4683
4719
  connectedCallback() {
4684
4720
  this._hasEverConnected = true;
4721
+ // Adapter capability marker without adding a field to the public class
4722
+ // declaration. React-node remove icons require the isolated root contract.
4723
+ this.setAttribute('data-smilodon-react-icon-portals', 'isolated-v1');
4685
4724
  // register instance
4686
4725
  EnhancedSelect._instances.add(this);
4687
4726
  this._runEngineEffects(this._engine.dispatch({ type: 'CONNECT' }));
4688
4727
  this._runEngineEffects(this._engine.dispatch({ type: 'DISABLED_CHANGED', disabled: !this._config.enabled }));
4689
4728
  this._connectionController?.abort();
4690
4729
  this._connectionController = new AbortController();
4730
+ this._observeSelectedLabelTooltipTargets();
4731
+ this._inputContent.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, { passive: true });
4691
4732
  document.addEventListener('pointerdown', this._onDocumentPointerDown, {
4692
4733
  signal: this._connectionController.signal,
4693
4734
  });
4735
+ window.addEventListener('resize', this._scheduleSelectedLabelTooltipMeasure, {
4736
+ signal: this._connectionController.signal,
4737
+ passive: true,
4738
+ });
4739
+ window.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, {
4740
+ signal: this._connectionController.signal,
4741
+ passive: true,
4742
+ capture: true,
4743
+ });
4694
4744
  // WORKAROUND: Force display style on host element for Angular compatibility
4695
4745
  // Angular's rendering seems to not apply :host styles correctly in some cases
4696
4746
  // Must be done in connectedCallback when element is attached to DOM
@@ -4741,6 +4791,7 @@ class EnhancedSelect extends HTMLElement {
4741
4791
  disconnectedCallback() {
4742
4792
  this._cancelOpenSelectedScroll();
4743
4793
  this._cancelLatestChipScroll();
4794
+ this._clearChipPresentation();
4744
4795
  this._cancelBusyPresentation();
4745
4796
  if (this._dataRequestCoordinator) {
4746
4797
  const actions = this._dataRequestCoordinator.disconnect();
@@ -4761,8 +4812,16 @@ class EnhancedSelect extends HTMLElement {
4761
4812
  this._handleClose('disconnect');
4762
4813
  }
4763
4814
  this._runEngineEffects(this._engine.dispatch({ type: 'DISCONNECT' }));
4815
+ this._inputContent.removeEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure);
4764
4816
  this._connectionController?.abort();
4765
4817
  this._connectionController = undefined;
4818
+ this._hideSelectedLabelTooltip(true);
4819
+ this._selectedLabelTooltipResizeObserver?.disconnect();
4820
+ this._selectedLabelTooltipResizeObserver = null;
4821
+ if (this._selectedLabelTooltipMeasureFrame !== null) {
4822
+ cancelAnimationFrame(this._selectedLabelTooltipMeasureFrame);
4823
+ this._selectedLabelTooltipMeasureFrame = null;
4824
+ }
4766
4825
  this._asyncGeneration += 1;
4767
4826
  this._cancelGuardedVirtualWindowUpdate();
4768
4827
  this._clearLifecycleTasks();
@@ -5694,12 +5753,25 @@ class EnhancedSelect extends HTMLElement {
5694
5753
  }
5695
5754
  _setIconContent(target, markup, fallback) {
5696
5755
  const content = markup && markup.trim() ? markup : fallback;
5697
- target.innerHTML = '';
5756
+ let fallbackTarget = target.querySelector(':scope > [data-smilodon-fallback-icon]');
5757
+ if (!fallbackTarget) {
5758
+ fallbackTarget = document.createElement('span');
5759
+ fallbackTarget.setAttribute('data-smilodon-fallback-icon', '');
5760
+ target.prepend(fallbackTarget);
5761
+ }
5762
+ if (!target.querySelector(':scope > [data-smilodon-react-icon-root]')) {
5763
+ const portalRoot = document.createElement('span');
5764
+ portalRoot.setAttribute('data-smilodon-react-icon-root', '');
5765
+ target.append(portalRoot);
5766
+ }
5767
+ // Only Core's fallback subtree is replaceable. React may reconcile a
5768
+ // separate portal root beneath this stable icon target.
5769
+ fallbackTarget.replaceChildren();
5698
5770
  if (content.trim().startsWith('<')) {
5699
- target.innerHTML = content;
5771
+ fallbackTarget.innerHTML = content;
5700
5772
  return;
5701
5773
  }
5702
- target.textContent = content;
5774
+ fallbackTarget.textContent = content;
5703
5775
  }
5704
5776
  _syncInputContainerMode() {
5705
5777
  if (!this._inputContainer || !this._input)
@@ -5914,6 +5986,35 @@ class EnhancedSelect extends HTMLElement {
5914
5986
  input.setAttribute('aria-haspopup', 'listbox');
5915
5987
  return input;
5916
5988
  }
5989
+ _createSelectedLabelTooltip() {
5990
+ const tooltip = document.createElement('div');
5991
+ tooltip.id = `${this._uniqueId}-selected-label-tooltip`;
5992
+ tooltip.className = 'selected-label-tooltip';
5993
+ tooltip.setAttribute('role', 'tooltip');
5994
+ tooltip.hidden = true;
5995
+ return tooltip;
5996
+ }
5997
+ _createSelectedLabelTooltipTextMeasure() {
5998
+ const measure = document.createElement('span');
5999
+ measure.setAttribute('aria-hidden', 'true');
6000
+ measure.dataset.selectInternal = 'tooltip-measure';
6001
+ measure.style.cssText = [
6002
+ 'all: initial',
6003
+ 'position: fixed',
6004
+ 'left: -100000px',
6005
+ 'top: 0',
6006
+ 'display: inline-block',
6007
+ 'width: max-content',
6008
+ 'height: auto',
6009
+ 'padding: 0',
6010
+ 'margin: 0',
6011
+ 'border: 0',
6012
+ 'white-space: pre',
6013
+ 'visibility: hidden',
6014
+ 'pointer-events: none',
6015
+ ].join(';');
6016
+ return measure;
6017
+ }
5917
6018
  _createDropdown() {
5918
6019
  const dropdown = document.createElement('div');
5919
6020
  dropdown.className = 'select-dropdown';
@@ -6008,6 +6109,8 @@ class EnhancedSelect extends HTMLElement {
6008
6109
  if (this._errorDescription) {
6009
6110
  this._shadow.appendChild(this._errorDescription);
6010
6111
  }
6112
+ this._shadow.appendChild(this._selectedLabelTooltip);
6113
+ this._shadow.appendChild(this._selectedLabelTooltipTextMeasure);
6011
6114
  // Set ARIA relationships
6012
6115
  const listboxId = `${this._uniqueId}-listbox`;
6013
6116
  this._dropdown.id = listboxId;
@@ -6022,6 +6125,12 @@ class EnhancedSelect extends HTMLElement {
6022
6125
  ELEGANT SELECT COMPONENT — Refined Design System
6023
6126
  Formal aesthetics with sophisticated microinteractions
6024
6127
  ═══════════════════════════════════════════════════════════════════════════ */
6128
+
6129
+ @layer smilodon-input-content-fallback {
6130
+ .input-container.input-container--multi:not([data-multi-scroll-mode="horizontal"]) .input-content {
6131
+ padding-inline-end: var(--select-multi-input-end-gap, 12px);
6132
+ }
6133
+ }
6025
6134
 
6026
6135
  :host {
6027
6136
  --select-primary: #1a1a2e;
@@ -6046,6 +6155,10 @@ class EnhancedSelect extends HTMLElement {
6046
6155
  --select-transition-smooth: 250ms cubic-bezier(0.4, 0, 0.2, 1);
6047
6156
  --select-transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
6048
6157
  --select-badge-animation: badgeEnter 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
6158
+ --select-badge-exit-from-opacity: 1;
6159
+ --select-badge-exit-from-transform: scale(1) translateY(0);
6160
+ --select-badge-exit-to-opacity: 0;
6161
+ --select-badge-exit-to-transform: scale(0.8) translateY(-4px);
6049
6162
  --select-badge-enter-from-opacity: 0;
6050
6163
  --select-badge-enter-from-transform: scale(0.8) translateY(-4px);
6051
6164
  --select-badge-enter-to-opacity: 1;
@@ -6247,7 +6360,13 @@ class EnhancedSelect extends HTMLElement {
6247
6360
  transform var(--select-transition-bounce),
6248
6361
  box-shadow var(--select-transition-fast),
6249
6362
  background var(--select-transition-fast);
6250
- animation: var(--select-badge-animation);
6363
+ animation: var(--select-badge-enter-animation, var(--select-badge-animation));
6364
+ }
6365
+
6366
+ .selection-badge[data-motion="exiting"] {
6367
+ animation: var(--select-badge-exit-animation, none);
6368
+ pointer-events: none;
6369
+ transition: none;
6251
6370
  }
6252
6371
 
6253
6372
  @keyframes badgeEnter {
@@ -6260,6 +6379,17 @@ class EnhancedSelect extends HTMLElement {
6260
6379
  transform: var(--select-badge-enter-to-transform);
6261
6380
  }
6262
6381
  }
6382
+
6383
+ @keyframes badgeExit {
6384
+ 0% {
6385
+ opacity: var(--select-badge-exit-from-opacity, 1);
6386
+ transform: var(--select-badge-exit-from-transform, scale(1) translateY(0));
6387
+ }
6388
+ 100% {
6389
+ opacity: var(--select-badge-exit-to-opacity, 0);
6390
+ transform: var(--select-badge-exit-to-transform, scale(0.8) translateY(-4px));
6391
+ }
6392
+ }
6263
6393
 
6264
6394
  .selection-badge:hover {
6265
6395
  background: var(--select-badge-hover-bg, var(--select-badge-bg, linear-gradient(135deg, var(--select-accent) 0%, var(--select-primary-light) 100%)));
@@ -6332,6 +6462,15 @@ class EnhancedSelect extends HTMLElement {
6332
6462
  pointer-events: none;
6333
6463
  }
6334
6464
 
6465
+ .badge-remove-icon > [data-smilodon-fallback-icon],
6466
+ .badge-remove-icon > [data-smilodon-react-icon-root] {
6467
+ display: contents;
6468
+ }
6469
+
6470
+ .badge-remove-icon[data-smilodon-icon-owner="react"] > [data-smilodon-fallback-icon] {
6471
+ display: none;
6472
+ }
6473
+
6335
6474
  .badge-remove-icon svg {
6336
6475
  width: 100%;
6337
6476
  height: 100%;
@@ -6372,6 +6511,29 @@ class EnhancedSelect extends HTMLElement {
6372
6511
  position: relative;
6373
6512
  width: 100%;
6374
6513
  }
6514
+
6515
+ .selected-label-tooltip {
6516
+ position: fixed;
6517
+ z-index: 2147483000;
6518
+ box-sizing: border-box;
6519
+ width: max-content;
6520
+ max-width: min(24rem, calc(100vw - 16px));
6521
+ padding: 8px 10px;
6522
+ border: 1px solid rgba(255, 255, 255, 0.18);
6523
+ border-radius: 6px;
6524
+ background: #18202e;
6525
+ color: #fff;
6526
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
6527
+ font: 500 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
6528
+ white-space: normal;
6529
+ overflow-wrap: anywhere;
6530
+ pointer-events: auto;
6531
+ direction: inherit;
6532
+ }
6533
+
6534
+ .selected-label-tooltip[hidden] {
6535
+ display: none;
6536
+ }
6375
6537
 
6376
6538
  .input-container {
6377
6539
  position: relative;
@@ -6420,6 +6582,7 @@ class EnhancedSelect extends HTMLElement {
6420
6582
  overflow-y: var(--select-input-overflow-y, hidden);
6421
6583
  scrollbar-width: thin;
6422
6584
  box-sizing: border-box;
6585
+ padding: var(--select-input-content-padding, revert-layer);
6423
6586
  }
6424
6587
 
6425
6588
  .input-container:hover {
@@ -6445,7 +6608,6 @@ class EnhancedSelect extends HTMLElement {
6445
6608
  align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
6446
6609
  overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
6447
6610
  overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
6448
- padding-inline-end: var(--select-multi-input-end-gap, 12px);
6449
6611
  }
6450
6612
 
6451
6613
  .input-container.input-container--multi .input-content .selection-badge {
@@ -6483,7 +6645,7 @@ class EnhancedSelect extends HTMLElement {
6483
6645
  overflow-y: hidden;
6484
6646
  overscroll-behavior-x: contain;
6485
6647
  overscroll-behavior-y: none;
6486
- padding-inline-end: 0;
6648
+ padding: var(--select-input-content-padding, 0);
6487
6649
  scroll-padding-inline-end: var(--select-multi-action-area-width, var(--select-arrow-width, 42px));
6488
6650
  }
6489
6651
 
@@ -6586,6 +6748,7 @@ class EnhancedSelect extends HTMLElement {
6586
6748
  bottom: 0;
6587
6749
  width: var(--select-arrow-width, var(--select-arrow-size, 42px));
6588
6750
  height: var(--select-arrow-height, var(--select-arrow-size, auto));
6751
+ padding: var(--select-dropdown-arrow-container-padding, 0);
6589
6752
  display: flex;
6590
6753
  align-items: center;
6591
6754
  justify-content: center;
@@ -7465,7 +7628,24 @@ class EnhancedSelect extends HTMLElement {
7465
7628
  this._shadow.appendChild(style);
7466
7629
  }
7467
7630
  }
7631
+ _isArrowOrClearControlEvent(event) {
7632
+ const path = event.composedPath();
7633
+ return ((this._arrowContainer != null && path.includes(this._arrowContainer)) ||
7634
+ (this._clearControl != null && path.includes(this._clearControl)));
7635
+ }
7468
7636
  _attachEventListeners() {
7637
+ this._shadow.addEventListener('pointerover', (event) => this._handleSelectedLabelPointerOver(event));
7638
+ this._shadow.addEventListener('pointerout', (event) => this._handleSelectedLabelPointerOut(event));
7639
+ this._shadow.addEventListener('focusin', (event) => this._handleSelectedLabelFocusIn(event));
7640
+ this._shadow.addEventListener('focusout', (event) => this._handleSelectedLabelFocusOut(event));
7641
+ this._shadow.addEventListener('keydown', (event) => {
7642
+ const keyboardEvent = event;
7643
+ if (keyboardEvent.key !== 'Escape' || this._selectedLabelTooltip.hidden)
7644
+ return;
7645
+ keyboardEvent.preventDefault();
7646
+ keyboardEvent.stopPropagation();
7647
+ this._dismissSelectedLabelTooltip();
7648
+ });
7469
7649
  // Arrow click handler
7470
7650
  if (this._arrowContainer) {
7471
7651
  this._boundArrowClick = (e) => {
@@ -7501,13 +7681,11 @@ class EnhancedSelect extends HTMLElement {
7501
7681
  // Prevent propagation to document click listener but do NOT preventDefault.
7502
7682
  // Allow default so browser events (click) on newly opened options still fire.
7503
7683
  // e.stopPropagation(); // BUG: By stopping propagation here, the document click listener doesn't see it, which is fine for not closing it. But be very careful.
7504
- const target = e.target;
7505
7684
  if (!this._config.enabled)
7506
7685
  return;
7507
- if (target && target.closest('.dropdown-arrow-container'))
7508
- return;
7509
- if (target && target.closest('.clear-control-button'))
7686
+ if (this._isArrowOrClearControlEvent(e))
7510
7687
  return;
7688
+ const target = e.target;
7511
7689
  if (this._isPointerOnInputScrollbar(e)) {
7512
7690
  this._suppressNextOpenClick = true;
7513
7691
  return;
@@ -7554,7 +7732,6 @@ class EnhancedSelect extends HTMLElement {
7554
7732
  }
7555
7733
  });
7556
7734
  this._inputContainer.addEventListener('click', (e) => {
7557
- const target = e.target;
7558
7735
  const isHorizontalMultiMode = this._config.selection.mode === 'multi'
7559
7736
  && (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal';
7560
7737
  if (!this._config.enabled || !isHorizontalMultiMode) {
@@ -7562,7 +7739,7 @@ class EnhancedSelect extends HTMLElement {
7562
7739
  this._multiScrollDrag.moved = false;
7563
7740
  return;
7564
7741
  }
7565
- if (target && target.closest('.dropdown-arrow-container, .clear-control-button')) {
7742
+ if (this._isArrowOrClearControlEvent(e)) {
7566
7743
  this._suppressNextOpenClick = false;
7567
7744
  this._multiScrollDrag.moved = false;
7568
7745
  return;
@@ -7637,6 +7814,9 @@ class EnhancedSelect extends HTMLElement {
7637
7814
  if (!this._config.searchable)
7638
7815
  return;
7639
7816
  const query = e.target.value;
7817
+ if (this._selectedLabelTooltipDismissedTrigger === this._input) {
7818
+ this._selectedLabelTooltipDismissedTrigger = null;
7819
+ }
7640
7820
  this._handleSearch(query);
7641
7821
  });
7642
7822
  // If the user presses down inside the options container we should
@@ -7799,6 +7979,340 @@ class EnhancedSelect extends HTMLElement {
7799
7979
  return index === undefined ? null : this._getOptionElementByIndex(index);
7800
7980
  },
7801
7981
  });
7982
+ this._syncSelectedLabelTooltipDescription();
7983
+ }
7984
+ _selectedLabelTriggerFromTarget(target) {
7985
+ if (!(target instanceof HTMLElement))
7986
+ return null;
7987
+ if (target === this._input)
7988
+ return target;
7989
+ const label = target.closest('.selection-badge-label');
7990
+ return label && this._inputContent.contains(label) ? label : null;
7991
+ }
7992
+ _getSelectedLabelForTrigger(trigger) {
7993
+ const entries = this._getSelectedEntries();
7994
+ if (trigger === this._input) {
7995
+ if (this._config.selection.mode !== 'single')
7996
+ return null;
7997
+ const item = entries[0]?.item;
7998
+ if (item === undefined)
7999
+ return null;
8000
+ const label = this._getItemLabel(item);
8001
+ return this._input.value === label ? label : null;
8002
+ }
8003
+ if (!trigger.classList.contains('selection-badge-label'))
8004
+ return null;
8005
+ const key = this._selectedLabelKeys.get(trigger);
8006
+ if (key === undefined)
8007
+ return null;
8008
+ const entry = entries.find((candidate) => candidate.key === key);
8009
+ if (!entry)
8010
+ return null;
8011
+ const label = this._getItemLabel(entry.item);
8012
+ return trigger.textContent === label ? label : null;
8013
+ }
8014
+ _isSelectedLabelTruncated(trigger) {
8015
+ if (!trigger.isConnected)
8016
+ return false;
8017
+ return trigger.clientWidth > 0 && trigger.scrollWidth > trigger.clientWidth + 1;
8018
+ }
8019
+ _getSelectedLabelTooltipContent(trigger) {
8020
+ if (trigger === this._input && this._config.searchable) {
8021
+ const visibleText = this._input.value;
8022
+ const pendingQuery = this._acknowledgedPendingSearchQuery;
8023
+ const committedQuery = this._state.searchQuery;
8024
+ const isPendingQuery = pendingQuery !== null && pendingQuery.length > 0 && visibleText === pendingQuery;
8025
+ const isCommittedQuery = committedQuery.length > 0 && visibleText === committedQuery;
8026
+ if (visibleText.length > 0 && (isPendingQuery || isCommittedQuery)) {
8027
+ return { kind: 'search-query', text: visibleText };
8028
+ }
8029
+ }
8030
+ const selectedLabel = this._getSelectedLabelForTrigger(trigger);
8031
+ return selectedLabel === null ? null : { kind: 'selected-label', text: selectedLabel };
8032
+ }
8033
+ _isSelectedLabelTooltipContentTruncated(trigger, content) {
8034
+ if (trigger !== this._input)
8035
+ return this._isSelectedLabelTruncated(trigger);
8036
+ if (!trigger.isConnected || !content.text)
8037
+ return false;
8038
+ const style = getComputedStyle(this._input);
8039
+ const measure = this._selectedLabelTooltipTextMeasure;
8040
+ measure.textContent = content.text;
8041
+ const mirroredProperties = [
8042
+ 'font',
8043
+ 'font-family',
8044
+ 'font-size',
8045
+ 'font-style',
8046
+ 'font-weight',
8047
+ 'font-stretch',
8048
+ 'font-variant',
8049
+ 'font-kerning',
8050
+ 'font-feature-settings',
8051
+ 'font-variation-settings',
8052
+ 'letter-spacing',
8053
+ 'word-spacing',
8054
+ 'text-transform',
8055
+ 'direction',
8056
+ 'unicode-bidi',
8057
+ ];
8058
+ for (const property of mirroredProperties) {
8059
+ const value = style.getPropertyValue(property);
8060
+ if (value)
8061
+ measure.style.setProperty(property, value);
8062
+ }
8063
+ const contentWidth = measure.getBoundingClientRect().width;
8064
+ const inputStyle = style;
8065
+ const horizontalPadding = Number.parseFloat(inputStyle.paddingLeft) + Number.parseFloat(inputStyle.paddingRight);
8066
+ const textIndent = Number.parseFloat(inputStyle.textIndent) || 0;
8067
+ const availableWidth = this._input.clientWidth - (Number.isFinite(horizontalPadding) ? horizontalPadding : 0) - textIndent;
8068
+ return availableWidth > 0 && contentWidth > availableWidth + 1;
8069
+ }
8070
+ _handleSelectedLabelPointerOver(event) {
8071
+ const target = event.target;
8072
+ if (target?.closest('.selected-label-tooltip') === this._selectedLabelTooltip) {
8073
+ this._selectedLabelTooltipPointerInside = true;
8074
+ this._clearSelectedLabelTooltipHideTimer();
8075
+ return;
8076
+ }
8077
+ const trigger = this._selectedLabelTriggerFromTarget(target);
8078
+ if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
8079
+ return;
8080
+ this._selectedLabelTooltipPointerTrigger = trigger;
8081
+ this._selectedLabelTooltipDismissedTrigger = null;
8082
+ this._showSelectedLabelTooltip(trigger);
8083
+ }
8084
+ _handleSelectedLabelPointerOut(event) {
8085
+ const target = event.target;
8086
+ if (target === this._selectedLabelTooltip || this._selectedLabelTooltip.contains(target)) {
8087
+ if (event.relatedTarget instanceof Node && this._selectedLabelTooltip.contains(event.relatedTarget))
8088
+ return;
8089
+ this._selectedLabelTooltipPointerInside = false;
8090
+ this._scheduleSelectedLabelTooltipHide();
8091
+ return;
8092
+ }
8093
+ const trigger = this._selectedLabelTriggerFromTarget(target);
8094
+ if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
8095
+ return;
8096
+ if (this._selectedLabelTooltipPointerTrigger === trigger) {
8097
+ this._selectedLabelTooltipPointerTrigger = null;
8098
+ if (this._selectedLabelTooltipDismissedTrigger === trigger) {
8099
+ this._selectedLabelTooltipDismissedTrigger = null;
8100
+ }
8101
+ }
8102
+ if (event.relatedTarget === this._selectedLabelTooltip) {
8103
+ this._selectedLabelTooltipPointerInside = true;
8104
+ this._clearSelectedLabelTooltipHideTimer();
8105
+ return;
8106
+ }
8107
+ this._scheduleSelectedLabelTooltipHide();
8108
+ }
8109
+ _handleSelectedLabelFocusIn(event) {
8110
+ const trigger = this._selectedLabelTriggerFromTarget(event.target);
8111
+ if (!trigger)
8112
+ return;
8113
+ this._selectedLabelTooltipFocusTrigger = trigger;
8114
+ this._selectedLabelTooltipDismissedTrigger = null;
8115
+ this._showSelectedLabelTooltip(trigger);
8116
+ }
8117
+ _handleSelectedLabelFocusOut(event) {
8118
+ const trigger = this._selectedLabelTriggerFromTarget(event.target);
8119
+ if (!trigger || this._selectedLabelTooltipFocusTrigger !== trigger)
8120
+ return;
8121
+ this._selectedLabelTooltipFocusTrigger = null;
8122
+ if (this._selectedLabelTooltipDismissedTrigger === trigger) {
8123
+ this._selectedLabelTooltipDismissedTrigger = null;
8124
+ }
8125
+ this._scheduleSelectedLabelTooltipHide();
8126
+ }
8127
+ _showSelectedLabelTooltip(trigger) {
8128
+ if (this._selectedLabelTooltipDismissedTrigger === trigger)
8129
+ return;
8130
+ if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
8131
+ if (this._selectedLabelTooltipTrigger === trigger)
8132
+ this._hideSelectedLabelTooltip();
8133
+ return;
8134
+ }
8135
+ const content = this._getSelectedLabelTooltipContent(trigger);
8136
+ if (content === null || !this._isSelectedLabelTooltipContentTruncated(trigger, content)) {
8137
+ if (trigger.classList.contains('selection-badge-label'))
8138
+ trigger.tabIndex = -1;
8139
+ if (this._selectedLabelTooltipTrigger === trigger)
8140
+ this._hideSelectedLabelTooltip();
8141
+ return;
8142
+ }
8143
+ if (trigger.classList.contains('selection-badge-label'))
8144
+ trigger.tabIndex = 0;
8145
+ if (this._selectedLabelTooltipTrigger !== trigger) {
8146
+ this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8147
+ this._selectedLabelTooltipTrigger = trigger;
8148
+ }
8149
+ this._selectedLabelTooltip.textContent = content.text;
8150
+ this._selectedLabelTooltip.hidden = false;
8151
+ this._positionSelectedLabelTooltip(trigger);
8152
+ this._syncSelectedLabelTooltipDescription();
8153
+ this._clearSelectedLabelTooltipHideTimer();
8154
+ }
8155
+ _positionSelectedLabelTooltip(trigger) {
8156
+ if (this._selectedLabelTooltip.hidden || !trigger.isConnected)
8157
+ return;
8158
+ const triggerRect = trigger.getBoundingClientRect();
8159
+ const tooltip = this._selectedLabelTooltip;
8160
+ tooltip.style.maxWidth = `min(24rem, calc(100vw - 16px))`;
8161
+ tooltip.style.direction = getComputedStyle(trigger).direction;
8162
+ const tooltipRect = tooltip.getBoundingClientRect();
8163
+ const viewportWidth = document.documentElement.clientWidth || window.innerWidth;
8164
+ const viewportHeight = document.documentElement.clientHeight || window.innerHeight;
8165
+ const rtl = getComputedStyle(trigger).direction === 'rtl';
8166
+ const desiredLeft = rtl ? triggerRect.right - tooltipRect.width : triggerRect.left;
8167
+ const left = Math.max(8, Math.min(desiredLeft, viewportWidth - tooltipRect.width - 8));
8168
+ const above = triggerRect.top - tooltipRect.height - 6;
8169
+ const top = above >= 8 ? above : Math.min(triggerRect.bottom + 6, viewportHeight - tooltipRect.height - 8);
8170
+ tooltip.style.left = `${left}px`;
8171
+ tooltip.style.top = `${Math.max(8, top)}px`;
8172
+ }
8173
+ _syncSelectedLabelTooltipDescription() {
8174
+ const trigger = this._selectedLabelTooltipTrigger;
8175
+ this._removeSelectedLabelTooltipDescription(trigger);
8176
+ if (trigger && !this._selectedLabelTooltip.hidden) {
8177
+ const ids = new Set((trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean));
8178
+ ids.add(this._selectedLabelTooltip.id);
8179
+ trigger.setAttribute('aria-describedby', [...ids].join(' '));
8180
+ }
8181
+ }
8182
+ _removeSelectedLabelTooltipDescription(trigger) {
8183
+ if (!trigger)
8184
+ return;
8185
+ const ids = (trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
8186
+ const remaining = ids.filter((id) => id !== this._selectedLabelTooltip.id);
8187
+ if (remaining.length)
8188
+ trigger.setAttribute('aria-describedby', remaining.join(' '));
8189
+ else
8190
+ trigger.removeAttribute('aria-describedby');
8191
+ }
8192
+ _dismissSelectedLabelTooltip() {
8193
+ this._selectedLabelTooltipDismissedTrigger = this._selectedLabelTooltipFocusTrigger
8194
+ ?? this._selectedLabelTooltipTrigger
8195
+ ?? this._selectedLabelTooltipPointerTrigger;
8196
+ this._hideSelectedLabelTooltip();
8197
+ }
8198
+ _hideSelectedLabelTooltip(clearInteractionState = false) {
8199
+ this._clearSelectedLabelTooltipHideTimer();
8200
+ this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8201
+ this._selectedLabelTooltipTrigger = null;
8202
+ this._selectedLabelTooltip.hidden = true;
8203
+ this._selectedLabelTooltipTextMeasure.textContent = '';
8204
+ if (clearInteractionState) {
8205
+ this._selectedLabelTooltipPointerTrigger = null;
8206
+ this._selectedLabelTooltipFocusTrigger = null;
8207
+ this._selectedLabelTooltipPointerInside = false;
8208
+ this._selectedLabelTooltipDismissedTrigger = null;
8209
+ }
8210
+ }
8211
+ _clearSelectedLabelTooltipHideTimer() {
8212
+ if (this._selectedLabelTooltipHideTimer === null)
8213
+ return;
8214
+ window.clearTimeout(this._selectedLabelTooltipHideTimer);
8215
+ this._lifecycleTimers.delete(this._selectedLabelTooltipHideTimer);
8216
+ this._selectedLabelTooltipHideTimer = null;
8217
+ }
8218
+ _scheduleSelectedLabelTooltipHide() {
8219
+ this._clearSelectedLabelTooltipHideTimer();
8220
+ this._selectedLabelTooltipHideTimer = this._setLifecycleTimeout(() => {
8221
+ this._selectedLabelTooltipHideTimer = null;
8222
+ if (this._selectedLabelTooltipPointerInside)
8223
+ return;
8224
+ const trigger = this._selectedLabelTooltipTrigger;
8225
+ if (trigger && (this._selectedLabelTooltipFocusTrigger === trigger
8226
+ || this._selectedLabelTooltipPointerTrigger === trigger))
8227
+ return;
8228
+ const focusedTrigger = this._selectedLabelTooltipFocusTrigger;
8229
+ if (focusedTrigger && focusedTrigger !== this._selectedLabelTooltipDismissedTrigger
8230
+ && focusedTrigger.isConnected
8231
+ && this._isSelectedLabelVisibleInViewport(focusedTrigger)) {
8232
+ this._showSelectedLabelTooltip(focusedTrigger);
8233
+ return;
8234
+ }
8235
+ this._hideSelectedLabelTooltip();
8236
+ }, 180);
8237
+ }
8238
+ _isSelectedLabelVisibleInViewport(trigger) {
8239
+ if (!trigger.classList.contains('selection-badge-label'))
8240
+ return true;
8241
+ const viewport = this._inputContent;
8242
+ const triggerRect = trigger.getBoundingClientRect();
8243
+ const viewportRect = viewport.getBoundingClientRect();
8244
+ // DOM-only test environments do not calculate layout rectangles. Leave
8245
+ // visibility indeterminate there; browser measurement handles real layout.
8246
+ if (triggerRect.width === 0 && triggerRect.height === 0
8247
+ && viewportRect.width === 0 && viewportRect.height === 0)
8248
+ return true;
8249
+ const left = viewportRect.left + viewport.clientLeft;
8250
+ const top = viewportRect.top + viewport.clientTop;
8251
+ const right = left + viewport.clientWidth;
8252
+ const bottom = top + viewport.clientHeight;
8253
+ return triggerRect.right > left && triggerRect.left < right
8254
+ && triggerRect.bottom > top && triggerRect.top < bottom;
8255
+ }
8256
+ _observeSelectedLabelTooltipTargets() {
8257
+ if (typeof ResizeObserver === 'undefined')
8258
+ return;
8259
+ const hasSingleSelection = this._config.selection.mode === 'single'
8260
+ && this._getSelectedEntries().length > 0;
8261
+ const inputContent = this._getSelectedLabelTooltipContent(this._input);
8262
+ const shouldObserveInput = hasSingleSelection || inputContent?.kind === 'search-query';
8263
+ const chipLabels = this._getActiveChipBadges()
8264
+ .map((badge) => badge.querySelector('.selection-badge-label'))
8265
+ .filter((label) => label !== null);
8266
+ if (!shouldObserveInput && chipLabels.length === 0) {
8267
+ this._selectedLabelTooltipResizeObserver?.disconnect();
8268
+ this._selectedLabelTooltipResizeObserver = null;
8269
+ return;
8270
+ }
8271
+ if (!this._selectedLabelTooltipResizeObserver) {
8272
+ this._selectedLabelTooltipResizeObserver = new ResizeObserver(() => this._scheduleSelectedLabelTooltipMeasure());
8273
+ }
8274
+ this._selectedLabelTooltipResizeObserver.disconnect();
8275
+ if (shouldObserveInput)
8276
+ this._selectedLabelTooltipResizeObserver.observe(this._input);
8277
+ chipLabels.forEach((label) => {
8278
+ this._selectedLabelTooltipResizeObserver?.observe(label);
8279
+ });
8280
+ }
8281
+ _refreshSelectedLabelTooltipMeasurements() {
8282
+ this._getActiveChipBadges().forEach((badge) => {
8283
+ const label = badge.querySelector('.selection-badge-label');
8284
+ if (!label)
8285
+ return;
8286
+ label.tabIndex = this._isSelectedLabelTruncated(label) ? 0 : -1;
8287
+ });
8288
+ const currentTrigger = this._selectedLabelTooltipTrigger;
8289
+ if (currentTrigger?.classList.contains('selection-badge-label')
8290
+ && !this._isSelectedLabelVisibleInViewport(currentTrigger)) {
8291
+ if (this._selectedLabelTooltipPointerTrigger === currentTrigger) {
8292
+ this._selectedLabelTooltipPointerTrigger = null;
8293
+ }
8294
+ this._hideSelectedLabelTooltip();
8295
+ }
8296
+ const trigger = this._selectedLabelTooltipTrigger
8297
+ ?? this._selectedLabelTooltipFocusTrigger
8298
+ ?? this._selectedLabelTooltipPointerTrigger;
8299
+ if (!trigger)
8300
+ return;
8301
+ if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
8302
+ if (this._selectedLabelTooltipPointerTrigger === trigger) {
8303
+ this._selectedLabelTooltipPointerTrigger = null;
8304
+ }
8305
+ if (this._selectedLabelTooltipTrigger === trigger)
8306
+ this._hideSelectedLabelTooltip();
8307
+ return;
8308
+ }
8309
+ const content = this._getSelectedLabelTooltipContent(trigger);
8310
+ if (content === null || !this._isSelectedLabelTooltipContentTruncated(trigger, content)) {
8311
+ if (this._selectedLabelTooltipTrigger === trigger)
8312
+ this._hideSelectedLabelTooltip();
8313
+ return;
8314
+ }
8315
+ this._showSelectedLabelTooltip(trigger);
7802
8316
  }
7803
8317
  _syncListboxAccessibility() {
7804
8318
  if (!this._dropdown || !this._engine || !this._state)
@@ -8395,6 +8909,8 @@ class EnhancedSelect extends HTMLElement {
8395
8909
  return results;
8396
8910
  }
8397
8911
  _handleSearch(query) {
8912
+ const previousQuery = this._acknowledgedPendingSearchQuery ?? this._state.searchQuery;
8913
+ const queryPresenceChanged = Boolean(previousQuery) !== Boolean(query);
8398
8914
  if (this._dataRequestCoordinator
8399
8915
  && (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)) {
8400
8916
  // Keep the committed query/generation stable until the accepted snapshot
@@ -8403,6 +8919,9 @@ class EnhancedSelect extends HTMLElement {
8403
8919
  this._acknowledgedPendingSearchQuery = query;
8404
8920
  this._input.value = query;
8405
8921
  this._syncClearControlState();
8922
+ if (queryPresenceChanged)
8923
+ this._observeSelectedLabelTooltipTargets();
8924
+ this._refreshSelectedLabelTooltipMeasurements();
8406
8925
  return;
8407
8926
  }
8408
8927
  if (this._dataLoadingConfig.protocol === 'acknowledged'
@@ -8414,6 +8933,9 @@ class EnhancedSelect extends HTMLElement {
8414
8933
  this._cancelBusyPresentation();
8415
8934
  this._state.searchQuery = query;
8416
8935
  this._syncClearControlState();
8936
+ if (queryPresenceChanged)
8937
+ this._observeSelectedLabelTooltipTargets();
8938
+ this._refreshSelectedLabelTooltipMeasurements();
8417
8939
  this._state.lastNotifiedQuery = query;
8418
8940
  this._state.lastNotifiedResultCount = 0;
8419
8941
  if (this._dataRequestCoordinator) {
@@ -8452,6 +8974,9 @@ class EnhancedSelect extends HTMLElement {
8452
8974
  }
8453
8975
  this._state.searchQuery = query;
8454
8976
  this._syncClearControlState();
8977
+ if (queryPresenceChanged)
8978
+ this._observeSelectedLabelTooltipTargets();
8979
+ this._refreshSelectedLabelTooltipMeasurements();
8455
8980
  if (this._dataLoadingConfig.protocol === 'acknowledged' && this._dataRequestCoordinator) {
8456
8981
  // Local acknowledged search has no remote request, but pagination still
8457
8982
  // belongs to the coordinator's current query generation.
@@ -8499,6 +9024,12 @@ class EnhancedSelect extends HTMLElement {
8499
9024
  }
8500
9025
  }
8501
9026
  _handleKeydown(e) {
9027
+ if (e.key === 'Escape' && !this._selectedLabelTooltip.hidden) {
9028
+ e.preventDefault();
9029
+ e.stopPropagation();
9030
+ this._dismissSelectedLabelTooltip();
9031
+ return;
9032
+ }
8502
9033
  if (!this._config.enabled)
8503
9034
  return;
8504
9035
  switch (e.key) {
@@ -8572,6 +9103,9 @@ class EnhancedSelect extends HTMLElement {
8572
9103
  break;
8573
9104
  case 'Enter':
8574
9105
  case ' ':
9106
+ if (e.key === ' ' && this._config.searchable && e.target === this._input) {
9107
+ break;
9108
+ }
8575
9109
  e.preventDefault();
8576
9110
  if (!this._state.isOpen) {
8577
9111
  this._handleOpen();
@@ -8595,7 +9129,8 @@ class EnhancedSelect extends HTMLElement {
8595
9129
  break;
8596
9130
  case 'a':
8597
9131
  case 'A':
8598
- if ((e.ctrlKey || e.metaKey) && this._config.selection.mode === 'multi') {
9132
+ if ((e.ctrlKey || e.metaKey) && !e.altKey
9133
+ && this._config.selection.mode === 'multi' && !this._config.searchable) {
8599
9134
  e.preventDefault();
8600
9135
  this._selectAll();
8601
9136
  }
@@ -9066,7 +9601,7 @@ class EnhancedSelect extends HTMLElement {
9066
9601
  : null;
9067
9602
  const hadFocusedChipRemove = focusedBadge !== null;
9068
9603
  const focusedBadgeIndex = focusedBadge
9069
- ? Array.from(this._inputContent.querySelectorAll('.selection-badge')).indexOf(focusedBadge)
9604
+ ? this._getActiveChipBadges().indexOf(focusedBadge)
9070
9605
  : -1;
9071
9606
  const option = this._itemRegistry.keyToRecord.has(entry.key)
9072
9607
  ? this._getOptionElementByIndex(entry.index)
@@ -9092,7 +9627,7 @@ class EnhancedSelect extends HTMLElement {
9092
9627
  this._renderOptions();
9093
9628
  this._emitChange();
9094
9629
  if (hadFocusedChipRemove && this.isConnected) {
9095
- const removeButtons = this._inputContent.querySelectorAll('[part="chip-remove"]');
9630
+ const removeButtons = this._getActiveChipRemoveButtons();
9096
9631
  if (removeButtons.length > 0) {
9097
9632
  const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9098
9633
  removeButtons[nextFocusIndex].focus();
@@ -9106,8 +9641,248 @@ class EnhancedSelect extends HTMLElement {
9106
9641
  : undefined;
9107
9642
  this._emit('remove', { item: config?.item ?? item, index: entry.index });
9108
9643
  }
9644
+ _getActiveChipBadges() {
9645
+ return Array.from(this._inputContent.querySelectorAll('.selection-badge'))
9646
+ .filter((badge) => badge.dataset.motion !== 'exiting' && !badge.hasAttribute('inert'));
9647
+ }
9648
+ _getActiveChipRemoveButtons() {
9649
+ return this._getActiveChipBadges()
9650
+ .map((badge) => badge.querySelector('[part="chip-remove"]'))
9651
+ .filter((button) => button !== null && !button.disabled);
9652
+ }
9653
+ _clearChipPresentation() {
9654
+ const badges = new Set(this._chipElements.values());
9655
+ const tooltipTriggers = [
9656
+ this._selectedLabelTooltipTrigger,
9657
+ this._selectedLabelTooltipPointerTrigger,
9658
+ this._selectedLabelTooltipFocusTrigger,
9659
+ this._selectedLabelTooltipDismissedTrigger,
9660
+ ];
9661
+ if (tooltipTriggers.some((trigger) => trigger !== null
9662
+ && Array.from(badges).some((badge) => badge.contains(trigger)))) {
9663
+ this._hideSelectedLabelTooltip(true);
9664
+ }
9665
+ for (const [key, state] of this._chipExitStates) {
9666
+ window.clearTimeout(state.timer);
9667
+ this._chipExitStates.delete(key);
9668
+ state.animations.forEach((animation) => animation.cancel());
9669
+ }
9670
+ for (const badge of this._chipElements.values()) {
9671
+ badge.removeAttribute('inert');
9672
+ badge.remove();
9673
+ }
9674
+ this._chipExitStates.clear();
9675
+ this._chipElements.clear();
9676
+ }
9677
+ _cancelChipExit(key, badge) {
9678
+ const state = this._chipExitStates.get(key);
9679
+ if (!state || state.badge !== badge)
9680
+ return;
9681
+ window.clearTimeout(state.timer);
9682
+ this._chipExitStates.delete(key);
9683
+ state.animations.forEach((animation) => animation.cancel());
9684
+ badge.removeAttribute('data-motion');
9685
+ badge.removeAttribute('aria-hidden');
9686
+ badge.removeAttribute('inert');
9687
+ badge.setAttribute('part', 'chip');
9688
+ const removeButton = badge.querySelector('[part="chip-remove"]');
9689
+ if (removeButton)
9690
+ removeButton.disabled = false;
9691
+ }
9692
+ _finishChipExit(key, expected) {
9693
+ const state = this._chipExitStates.get(key);
9694
+ if (!state || state.badge !== expected)
9695
+ return;
9696
+ window.clearTimeout(state.timer);
9697
+ this._chipExitStates.delete(key);
9698
+ state.animations.forEach((animation) => {
9699
+ if (animation.playState !== 'finished')
9700
+ animation.cancel();
9701
+ });
9702
+ this._chipElements.delete(key);
9703
+ expected.remove();
9704
+ if (this.isConnected) {
9705
+ this._observeSelectedLabelTooltipTargets();
9706
+ this._refreshSelectedLabelTooltipMeasurements();
9707
+ }
9708
+ }
9709
+ _moveFocusOutOfChip(badge) {
9710
+ const activeElement = this._shadow.activeElement;
9711
+ if (!(activeElement instanceof HTMLElement) || !badge.contains(activeElement))
9712
+ return;
9713
+ const badges = this._getActiveChipBadges().filter((candidate) => candidate !== badge);
9714
+ const oldIndex = Array.from(this._inputContent.querySelectorAll('.selection-badge')).indexOf(badge);
9715
+ const buttons = badges
9716
+ .map((candidate) => candidate.querySelector('[part="chip-remove"]'))
9717
+ .filter((button) => button !== null && !button.disabled);
9718
+ const next = buttons[Math.min(Math.max(oldIndex, 0), buttons.length - 1)];
9719
+ if (next)
9720
+ next.focus({ preventScroll: true });
9721
+ else
9722
+ this._input.focus({ preventScroll: true });
9723
+ }
9724
+ _beginChipExit(key, badge) {
9725
+ if (this._chipExitStates.has(key))
9726
+ return;
9727
+ this._moveFocusOutOfChip(badge);
9728
+ const label = badge.querySelector('.selection-badge-label');
9729
+ if (label) {
9730
+ this._removeSelectedLabelTooltipDescription(label);
9731
+ label.tabIndex = -1;
9732
+ if (this._selectedLabelTooltipPointerTrigger === label)
9733
+ this._selectedLabelTooltipPointerTrigger = null;
9734
+ if (this._selectedLabelTooltipFocusTrigger === label)
9735
+ this._selectedLabelTooltipFocusTrigger = null;
9736
+ if (this._selectedLabelTooltipDismissedTrigger === label)
9737
+ this._selectedLabelTooltipDismissedTrigger = null;
9738
+ if (this._selectedLabelTooltipTrigger === label)
9739
+ this._hideSelectedLabelTooltip();
9740
+ }
9741
+ badge.dataset.motion = 'exiting';
9742
+ badge.setAttribute('aria-hidden', 'true');
9743
+ badge.setAttribute('inert', '');
9744
+ badge.setAttribute('part', 'chip-exiting');
9745
+ const removeButton = badge.querySelector('[part="chip-remove"]');
9746
+ if (removeButton)
9747
+ removeButton.disabled = true;
9748
+ // Force style resolution after the exiting part is exposed. This also
9749
+ // verifies that a consumer keyframe is actually available across Shadow DOM.
9750
+ badge.getBoundingClientRect();
9751
+ const animations = (typeof badge.getAnimations === 'function' ? badge.getAnimations() : []).filter((animation) => {
9752
+ const cssAnimation = animation;
9753
+ return typeof cssAnimation.animationName === 'string'
9754
+ && cssAnimation.animationName !== 'none'
9755
+ && animation.playState !== 'idle';
9756
+ });
9757
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
9758
+ if (reducedMotion || animations.length === 0) {
9759
+ badge.removeAttribute('data-motion');
9760
+ this._chipExitStates.set(key, { badge, animations: [], timer: 0 });
9761
+ this._finishChipExit(key, badge);
9762
+ return;
9763
+ }
9764
+ const endTimes = animations.map((animation) => Number(animation.effect?.getComputedTiming().endTime ?? 0));
9765
+ const maxEndTime = Math.max(0, ...endTimes);
9766
+ const fallbackDelay = Math.min(Number.isFinite(maxEndTime) ? maxEndTime + 100 : 1000, 5000);
9767
+ const timer = window.setTimeout(() => this._finishChipExit(key, badge), fallbackDelay);
9768
+ this._chipExitStates.set(key, { badge, animations, timer });
9769
+ void Promise.allSettled(animations.map((animation) => animation.finished))
9770
+ .then(() => this._finishChipExit(key, badge));
9771
+ }
9772
+ _createChip(key) {
9773
+ const badge = document.createElement('span');
9774
+ badge.className = 'selection-badge';
9775
+ badge.setAttribute('part', 'chip');
9776
+ const label = document.createElement('span');
9777
+ label.className = 'selection-badge-label';
9778
+ label.setAttribute('part', 'chip-label');
9779
+ this._selectedLabelKeys.set(label, key);
9780
+ badge.appendChild(label);
9781
+ this._chipElements.set(key, badge);
9782
+ return badge;
9783
+ }
9784
+ _updateChip(key, index, item, badge) {
9785
+ const getLabel = this._config.serverSide.getLabelFromItem || ((value) => value?.label ?? String(value));
9786
+ const labelText = getLabel(item);
9787
+ badge.className = 'selection-badge';
9788
+ if (this._config.styles.classNames?.badge) {
9789
+ badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
9790
+ }
9791
+ badge.setAttribute('part', 'chip');
9792
+ badge.removeAttribute('aria-hidden');
9793
+ badge.removeAttribute('inert');
9794
+ badge.removeAttribute('data-motion');
9795
+ const label = badge.querySelector('.selection-badge-label');
9796
+ label.className = 'selection-badge-label';
9797
+ if (this._config.styles.classNames?.badgeLabel) {
9798
+ label.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
9799
+ }
9800
+ label.textContent = labelText;
9801
+ this._selectedLabelKeys.set(label, key);
9802
+ const shouldShowRemove = this._config.selection.showRemoveButton !== false;
9803
+ let removeButton = badge.querySelector('[part="chip-remove"]');
9804
+ if (!shouldShowRemove) {
9805
+ removeButton?.remove();
9806
+ return;
9807
+ }
9808
+ if (!removeButton) {
9809
+ removeButton = document.createElement('button');
9810
+ removeButton.type = 'button';
9811
+ removeButton.addEventListener('pointerdown', (event) => {
9812
+ event.stopPropagation();
9813
+ event.preventDefault();
9814
+ });
9815
+ removeButton.addEventListener('click', (event) => {
9816
+ event.stopPropagation();
9817
+ event.preventDefault();
9818
+ this._handleOptionRemove(index, key);
9819
+ });
9820
+ const removeIcon = document.createElement('span');
9821
+ removeIcon.className = 'badge-remove-icon';
9822
+ removeIcon.setAttribute('part', 'chip-remove-icon');
9823
+ removeButton.appendChild(removeIcon);
9824
+ badge.appendChild(removeButton);
9825
+ }
9826
+ removeButton.className = 'badge-remove';
9827
+ if (this._config.styles.classNames?.removeButton) {
9828
+ removeButton.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
9829
+ }
9830
+ if (this._config.styles.classNames?.badgeRemove) {
9831
+ removeButton.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
9832
+ }
9833
+ removeButton.setAttribute('part', 'chip-remove');
9834
+ removeButton.setAttribute('aria-label', `Remove ${labelText}`);
9835
+ removeButton.disabled = false;
9836
+ const removeIcon = removeButton.querySelector('[part="chip-remove-icon"]');
9837
+ removeIcon.className = 'badge-remove-icon';
9838
+ if (this._config.styles.classNames?.badgeRemoveIcon) {
9839
+ removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
9840
+ }
9841
+ this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
9842
+ }
9843
+ _renderSelectedChips(entries) {
9844
+ const selectedKeys = new Set(entries.map(({ key }) => key));
9845
+ for (const { key, index, item } of entries) {
9846
+ let badge = this._chipElements.get(key);
9847
+ if (!badge)
9848
+ badge = this._createChip(key);
9849
+ this._cancelChipExit(key, badge);
9850
+ this._updateChip(key, index, item, badge);
9851
+ }
9852
+ for (const [key, badge] of this._chipElements) {
9853
+ if (!selectedKeys.has(key))
9854
+ this._beginChipExit(key, badge);
9855
+ }
9856
+ // Do not move chips merely because another chip entered its exit period.
9857
+ // That keeps the exiting chip in its original layout slot while the active
9858
+ // sequence remains correct. Reorder only when selected-key order changed.
9859
+ const desiredBadges = entries
9860
+ .map(({ key }) => this._chipElements.get(key))
9861
+ .filter((badge) => badge !== undefined);
9862
+ const currentBadges = this._getActiveChipBadges();
9863
+ const orderChanged = desiredBadges.length !== currentBadges.length
9864
+ || desiredBadges.some((badge, index) => badge !== currentBadges[index]);
9865
+ if (orderChanged) {
9866
+ let nextSibling = this._input;
9867
+ for (let index = desiredBadges.length - 1; index >= 0; index -= 1) {
9868
+ const badge = desiredBadges[index];
9869
+ if (badge.nextSibling !== nextSibling)
9870
+ this._inputContent.insertBefore(badge, nextSibling);
9871
+ nextSibling = badge;
9872
+ }
9873
+ }
9874
+ }
9109
9875
  _updateInputDisplay() {
9110
9876
  const selectedEntries = this._getSelectedEntries();
9877
+ const focusedElement = this._shadow.activeElement;
9878
+ const focusedSelectedKey = focusedElement?.classList.contains('selection-badge-label')
9879
+ ? this._selectedLabelKeys.get(focusedElement) ?? null
9880
+ : null;
9881
+ const focusedBadge = focusedElement?.closest('.selection-badge');
9882
+ const focusedChipKey = focusedBadge
9883
+ ? Array.from(this._chipElements.entries()).find(([, badge]) => badge === focusedBadge)?.[0] ?? null
9884
+ : null;
9885
+ const focusedBadgeIndex = focusedBadge ? this._getActiveChipBadges().indexOf(focusedBadge) : -1;
9111
9886
  const selectedItems = selectedEntries.map(({ item }) => item);
9112
9887
  const nextKeys = new Set(selectedEntries.map(({ key }) => key));
9113
9888
  const previousKeys = this._lastRenderedChipKeys;
@@ -9123,73 +9898,27 @@ class EnhancedSelect extends HTMLElement {
9123
9898
  // Only a newly added selected key can initiate auto-scroll.
9124
9899
  this._cancelLatestChipScroll();
9125
9900
  const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
9126
- if (selectedItems.length === 0) {
9127
- this._input.value = '';
9128
- this._input.placeholder = this._config.placeholder || 'Select an option...';
9129
- // Clear any badges
9130
- const existingBadges = this._inputContent.querySelectorAll('.selection-badge');
9131
- existingBadges.forEach(badge => badge.remove());
9132
- }
9133
- else if (this._config.selection.mode === 'single') {
9134
- this._input.value = getLabel(selectedItems[0]);
9901
+ if (this._config.selection.mode === 'multi') {
9902
+ if (selectedItems.length === 0) {
9903
+ this._input.value = '';
9904
+ this._input.placeholder = this._config.placeholder || 'Select an option...';
9905
+ }
9906
+ else {
9907
+ this._input.value = '';
9908
+ this._input.placeholder = '';
9909
+ }
9910
+ this._renderSelectedChips(selectedEntries);
9135
9911
  }
9136
9912
  else {
9137
- // Multi-select: show badges instead of text in input
9138
- this._input.value = '';
9139
- this._input.placeholder = '';
9140
- // Clear existing badges
9141
- const existingBadges = this._inputContent.querySelectorAll('.selection-badge');
9142
- existingBadges.forEach(badge => badge.remove());
9143
- // Create badges for each selected item
9144
- selectedEntries.forEach(({ key, index, item }) => {
9145
- const badge = document.createElement('span');
9146
- badge.className = 'selection-badge';
9147
- if (this._config.styles.classNames?.badge) {
9148
- badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
9149
- }
9150
- badge.setAttribute('part', 'chip');
9151
- const badgeLabel = document.createElement('span');
9152
- badgeLabel.className = 'selection-badge-label';
9153
- if (this._config.styles.classNames?.badgeLabel) {
9154
- badgeLabel.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
9155
- }
9156
- badgeLabel.setAttribute('part', 'chip-label');
9157
- badgeLabel.textContent = getLabel(item);
9158
- badge.appendChild(badgeLabel);
9159
- // Add remove button to badge
9160
- if (this._config.selection.showRemoveButton !== false) {
9161
- const removeBtn = document.createElement('button');
9162
- removeBtn.type = 'button';
9163
- removeBtn.className = 'badge-remove';
9164
- if (this._config.styles.classNames?.removeButton) {
9165
- removeBtn.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
9166
- }
9167
- if (this._config.styles.classNames?.badgeRemove) {
9168
- removeBtn.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
9169
- }
9170
- removeBtn.setAttribute('part', 'chip-remove');
9171
- removeBtn.setAttribute('aria-label', `Remove ${getLabel(item)}`);
9172
- const removeIcon = document.createElement('span');
9173
- removeIcon.className = 'badge-remove-icon';
9174
- if (this._config.styles.classNames?.badgeRemoveIcon) {
9175
- removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
9176
- }
9177
- removeIcon.setAttribute('part', 'chip-remove-icon');
9178
- this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
9179
- removeBtn.appendChild(removeIcon);
9180
- removeBtn.addEventListener('pointerdown', (e) => {
9181
- e.stopPropagation();
9182
- e.preventDefault();
9183
- });
9184
- removeBtn.addEventListener('click', (e) => {
9185
- e.stopPropagation();
9186
- e.preventDefault();
9187
- this._handleOptionRemove(index, key);
9188
- });
9189
- badge.appendChild(removeBtn);
9190
- }
9191
- this._inputContent.insertBefore(badge, this._input);
9192
- });
9913
+ // A mode switch ends visual exits immediately; a single-select has no chip presentation.
9914
+ this._clearChipPresentation();
9915
+ if (selectedItems.length === 0) {
9916
+ this._input.value = '';
9917
+ this._input.placeholder = this._config.placeholder || 'Select an option...';
9918
+ }
9919
+ else {
9920
+ this._input.value = getLabel(selectedItems[0]);
9921
+ }
9193
9922
  }
9194
9923
  // A query typed during an accepted-snapshot projection is a pending user
9195
9924
  // intent, not part of the committed projection state. Keep it visible even
@@ -9197,14 +9926,60 @@ class EnhancedSelect extends HTMLElement {
9197
9926
  if (this._acknowledgedPendingSearchQuery !== null) {
9198
9927
  this._input.value = this._acknowledgedPendingSearchQuery;
9199
9928
  }
9200
- // Recreating the chip DOM must not reset manual scrolling. In particular,
9201
- // remove/clear, config rerenders, and item refreshes are not scroll intents.
9929
+ // Preserve manual scrolling. Only a newly selected key can request auto-scroll.
9202
9930
  if (this._config.selection.mode === 'multi') {
9203
9931
  this._inputContent.scrollLeft = previousChipScrollLeft;
9204
9932
  if (newlyAddedKey !== undefined)
9205
9933
  this._scheduleLatestChipScroll(newlyAddedKey);
9206
9934
  }
9207
9935
  this._syncClearControlState();
9936
+ this._observeSelectedLabelTooltipTargets();
9937
+ this._refreshSelectedLabelTooltipMeasurements();
9938
+ if (focusedChipKey !== null && !nextKeys.has(focusedChipKey)) {
9939
+ const removeButtons = this._getActiveChipRemoveButtons();
9940
+ if (removeButtons.length > 0) {
9941
+ const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9942
+ removeButtons[nextFocusIndex].focus({ preventScroll: true });
9943
+ }
9944
+ else {
9945
+ this._input.focus({ preventScroll: true });
9946
+ }
9947
+ }
9948
+ else if (focusedChipKey !== null && focusedElement && !focusedElement.isConnected) {
9949
+ const badge = this._chipElements.get(focusedChipKey);
9950
+ const removeButton = badge?.querySelector('[part="chip-remove"]');
9951
+ if (removeButton && !removeButton.disabled)
9952
+ removeButton.focus({ preventScroll: true });
9953
+ else
9954
+ this._input.focus({ preventScroll: true });
9955
+ }
9956
+ else if (focusedSelectedKey !== null) {
9957
+ const replacement = this._getActiveChipBadges()
9958
+ .map((badge) => badge.querySelector('.selection-badge-label'))
9959
+ .find((label) => label && this._selectedLabelKeys.get(label) === focusedSelectedKey);
9960
+ if (!replacement) {
9961
+ const removeButtons = this._getActiveChipRemoveButtons();
9962
+ if (removeButtons.length > 0) {
9963
+ const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9964
+ removeButtons[nextFocusIndex].focus({ preventScroll: true });
9965
+ }
9966
+ else {
9967
+ this._input.focus({ preventScroll: true });
9968
+ }
9969
+ }
9970
+ else if (this._isSelectedLabelTruncated(replacement)) {
9971
+ // The measurement pass assigns the tab stop before focus restoration.
9972
+ replacement.tabIndex = 0;
9973
+ replacement.focus({ preventScroll: true });
9974
+ }
9975
+ else {
9976
+ this._input.focus({ preventScroll: true });
9977
+ }
9978
+ }
9979
+ if (this._selectedLabelTooltipFocusTrigger === this._input
9980
+ || this._selectedLabelTooltipPointerTrigger === this._input) {
9981
+ this._showSelectedLabelTooltip(this._input);
9982
+ }
9208
9983
  }
9209
9984
  _cancelLatestChipScroll() {
9210
9985
  this._latestChipScrollGeneration += 1;
@@ -9236,7 +10011,7 @@ class EnhancedSelect extends HTMLElement {
9236
10011
  const index = entries.findIndex((entry) => entry.key === key);
9237
10012
  if (index < 0)
9238
10013
  return;
9239
- const chip = this._inputContent.querySelectorAll('.selection-badge')[index];
10014
+ const chip = this._getActiveChipBadges()[index];
9240
10015
  if (!chip)
9241
10016
  return;
9242
10017
  const hostBounds = this._inputContent.getBoundingClientRect();
@@ -9824,6 +10599,8 @@ class EnhancedSelect extends HTMLElement {
9824
10599
  }
9825
10600
  this._renderOptions();
9826
10601
  this._syncClearControlState();
10602
+ this._observeSelectedLabelTooltipTargets();
10603
+ this._refreshSelectedLabelTooltipMeasurements();
9827
10604
  }
9828
10605
  /**
9829
10606
  * Open dropdown
@@ -10032,6 +10809,8 @@ class EnhancedSelect extends HTMLElement {
10032
10809
  }
10033
10810
  }
10034
10811
  }
10812
+ this._observeSelectedLabelTooltipTargets();
10813
+ this._refreshSelectedLabelTooltipMeasurements();
10035
10814
  if (configErrorDetail) {
10036
10815
  this._emit('dataLoadingConfigError', configErrorDetail);
10037
10816
  try {