@smilodon/core 1.20.0 → 1.21.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.js CHANGED
@@ -4443,6 +4443,15 @@ class EnhancedSelect extends HTMLElement {
4443
4443
  super();
4444
4444
  this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
4445
4445
  this._hasLastInvalidDataLoadingCandidate = false;
4446
+ this._selectedLabelTooltipTrigger = null;
4447
+ this._selectedLabelTooltipPointerTrigger = null;
4448
+ this._selectedLabelTooltipFocusTrigger = null;
4449
+ this._selectedLabelTooltipPointerInside = false;
4450
+ this._selectedLabelTooltipDismissedTrigger = null;
4451
+ this._selectedLabelTooltipHideTimer = null;
4452
+ this._selectedLabelTooltipResizeObserver = null;
4453
+ this._selectedLabelTooltipMeasureFrame = null;
4454
+ this._selectedLabelKeys = new WeakMap();
4446
4455
  this._busyPresentationVisible = false;
4447
4456
  this._busyPresentationStartedAt = null;
4448
4457
  this._busyPresentationGeneration = 0;
@@ -4542,6 +4551,9 @@ class EnhancedSelect extends HTMLElement {
4542
4551
  this._rangeAnchorKey = null;
4543
4552
  /** Chip identity is tracked independently of dropdown option positions. */
4544
4553
  this._lastRenderedChipKeys = null;
4554
+ /** Stable presentation nodes keyed by the engine's selected-item identity. */
4555
+ this._chipElements = new Map();
4556
+ this._chipExitStates = new Map();
4545
4557
  this._latestChipScrollGeneration = 0;
4546
4558
  this._latestChipScrollFrame = null;
4547
4559
  this._customOptionBoundElements = new WeakSet();
@@ -4627,6 +4639,14 @@ class EnhancedSelect extends HTMLElement {
4627
4639
  this._handleClose('outside-pointer');
4628
4640
  }
4629
4641
  };
4642
+ this._scheduleSelectedLabelTooltipMeasure = () => {
4643
+ if (this._selectedLabelTooltipMeasureFrame !== null || !this.isConnected)
4644
+ return;
4645
+ this._selectedLabelTooltipMeasureFrame = this._requestLifecycleFrame(() => {
4646
+ this._selectedLabelTooltipMeasureFrame = null;
4647
+ this._refreshSelectedLabelTooltipMeasurements();
4648
+ });
4649
+ };
4630
4650
  this._shadow = this.attachShadow({ mode: 'open' });
4631
4651
  this._uniqueId = `enhanced-select-${Math.random().toString(36).substr(2, 9)}`;
4632
4652
  this._rendererHelpers = this._buildRendererHelpers();
@@ -4661,6 +4681,7 @@ class EnhancedSelect extends HTMLElement {
4661
4681
  this._inputContainer = this._createInputContainer();
4662
4682
  this._inputContent = this._createInputContent();
4663
4683
  this._input = this._createInput();
4684
+ this._selectedLabelTooltip = this._createSelectedLabelTooltip();
4664
4685
  this._arrowContainer = this._createArrowContainer();
4665
4686
  this._clearControl = this._createClearControl();
4666
4687
  this._dropdown = this._createDropdown();
@@ -4686,9 +4707,19 @@ class EnhancedSelect extends HTMLElement {
4686
4707
  this._runEngineEffects(this._engine.dispatch({ type: 'DISABLED_CHANGED', disabled: !this._config.enabled }));
4687
4708
  this._connectionController?.abort();
4688
4709
  this._connectionController = new AbortController();
4710
+ this._observeSelectedLabelTooltipTargets();
4689
4711
  document.addEventListener('pointerdown', this._onDocumentPointerDown, {
4690
4712
  signal: this._connectionController.signal,
4691
4713
  });
4714
+ window.addEventListener('resize', this._scheduleSelectedLabelTooltipMeasure, {
4715
+ signal: this._connectionController.signal,
4716
+ passive: true,
4717
+ });
4718
+ window.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, {
4719
+ signal: this._connectionController.signal,
4720
+ passive: true,
4721
+ capture: true,
4722
+ });
4692
4723
  // WORKAROUND: Force display style on host element for Angular compatibility
4693
4724
  // Angular's rendering seems to not apply :host styles correctly in some cases
4694
4725
  // Must be done in connectedCallback when element is attached to DOM
@@ -4739,6 +4770,7 @@ class EnhancedSelect extends HTMLElement {
4739
4770
  disconnectedCallback() {
4740
4771
  this._cancelOpenSelectedScroll();
4741
4772
  this._cancelLatestChipScroll();
4773
+ this._clearChipPresentation();
4742
4774
  this._cancelBusyPresentation();
4743
4775
  if (this._dataRequestCoordinator) {
4744
4776
  const actions = this._dataRequestCoordinator.disconnect();
@@ -4761,6 +4793,13 @@ class EnhancedSelect extends HTMLElement {
4761
4793
  this._runEngineEffects(this._engine.dispatch({ type: 'DISCONNECT' }));
4762
4794
  this._connectionController?.abort();
4763
4795
  this._connectionController = undefined;
4796
+ this._hideSelectedLabelTooltip(true);
4797
+ this._selectedLabelTooltipResizeObserver?.disconnect();
4798
+ this._selectedLabelTooltipResizeObserver = null;
4799
+ if (this._selectedLabelTooltipMeasureFrame !== null) {
4800
+ cancelAnimationFrame(this._selectedLabelTooltipMeasureFrame);
4801
+ this._selectedLabelTooltipMeasureFrame = null;
4802
+ }
4764
4803
  this._asyncGeneration += 1;
4765
4804
  this._cancelGuardedVirtualWindowUpdate();
4766
4805
  this._clearLifecycleTasks();
@@ -5912,6 +5951,14 @@ class EnhancedSelect extends HTMLElement {
5912
5951
  input.setAttribute('aria-haspopup', 'listbox');
5913
5952
  return input;
5914
5953
  }
5954
+ _createSelectedLabelTooltip() {
5955
+ const tooltip = document.createElement('div');
5956
+ tooltip.id = `${this._uniqueId}-selected-label-tooltip`;
5957
+ tooltip.className = 'selected-label-tooltip';
5958
+ tooltip.setAttribute('role', 'tooltip');
5959
+ tooltip.hidden = true;
5960
+ return tooltip;
5961
+ }
5915
5962
  _createDropdown() {
5916
5963
  const dropdown = document.createElement('div');
5917
5964
  dropdown.className = 'select-dropdown';
@@ -6006,6 +6053,7 @@ class EnhancedSelect extends HTMLElement {
6006
6053
  if (this._errorDescription) {
6007
6054
  this._shadow.appendChild(this._errorDescription);
6008
6055
  }
6056
+ this._shadow.appendChild(this._selectedLabelTooltip);
6009
6057
  // Set ARIA relationships
6010
6058
  const listboxId = `${this._uniqueId}-listbox`;
6011
6059
  this._dropdown.id = listboxId;
@@ -6020,6 +6068,12 @@ class EnhancedSelect extends HTMLElement {
6020
6068
  ELEGANT SELECT COMPONENT — Refined Design System
6021
6069
  Formal aesthetics with sophisticated microinteractions
6022
6070
  ═══════════════════════════════════════════════════════════════════════════ */
6071
+
6072
+ @layer smilodon-input-content-fallback {
6073
+ .input-container.input-container--multi:not([data-multi-scroll-mode="horizontal"]) .input-content {
6074
+ padding-inline-end: var(--select-multi-input-end-gap, 12px);
6075
+ }
6076
+ }
6023
6077
 
6024
6078
  :host {
6025
6079
  --select-primary: #1a1a2e;
@@ -6044,6 +6098,10 @@ class EnhancedSelect extends HTMLElement {
6044
6098
  --select-transition-smooth: 250ms cubic-bezier(0.4, 0, 0.2, 1);
6045
6099
  --select-transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
6046
6100
  --select-badge-animation: badgeEnter 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
6101
+ --select-badge-exit-from-opacity: 1;
6102
+ --select-badge-exit-from-transform: scale(1) translateY(0);
6103
+ --select-badge-exit-to-opacity: 0;
6104
+ --select-badge-exit-to-transform: scale(0.8) translateY(-4px);
6047
6105
  --select-badge-enter-from-opacity: 0;
6048
6106
  --select-badge-enter-from-transform: scale(0.8) translateY(-4px);
6049
6107
  --select-badge-enter-to-opacity: 1;
@@ -6245,7 +6303,13 @@ class EnhancedSelect extends HTMLElement {
6245
6303
  transform var(--select-transition-bounce),
6246
6304
  box-shadow var(--select-transition-fast),
6247
6305
  background var(--select-transition-fast);
6248
- animation: var(--select-badge-animation);
6306
+ animation: var(--select-badge-enter-animation, var(--select-badge-animation));
6307
+ }
6308
+
6309
+ .selection-badge[data-motion="exiting"] {
6310
+ animation: var(--select-badge-exit-animation, none);
6311
+ pointer-events: none;
6312
+ transition: none;
6249
6313
  }
6250
6314
 
6251
6315
  @keyframes badgeEnter {
@@ -6258,6 +6322,17 @@ class EnhancedSelect extends HTMLElement {
6258
6322
  transform: var(--select-badge-enter-to-transform);
6259
6323
  }
6260
6324
  }
6325
+
6326
+ @keyframes badgeExit {
6327
+ 0% {
6328
+ opacity: var(--select-badge-exit-from-opacity, 1);
6329
+ transform: var(--select-badge-exit-from-transform, scale(1) translateY(0));
6330
+ }
6331
+ 100% {
6332
+ opacity: var(--select-badge-exit-to-opacity, 0);
6333
+ transform: var(--select-badge-exit-to-transform, scale(0.8) translateY(-4px));
6334
+ }
6335
+ }
6261
6336
 
6262
6337
  .selection-badge:hover {
6263
6338
  background: var(--select-badge-hover-bg, var(--select-badge-bg, linear-gradient(135deg, var(--select-accent) 0%, var(--select-primary-light) 100%)));
@@ -6370,6 +6445,29 @@ class EnhancedSelect extends HTMLElement {
6370
6445
  position: relative;
6371
6446
  width: 100%;
6372
6447
  }
6448
+
6449
+ .selected-label-tooltip {
6450
+ position: fixed;
6451
+ z-index: 2147483000;
6452
+ box-sizing: border-box;
6453
+ width: max-content;
6454
+ max-width: min(24rem, calc(100vw - 16px));
6455
+ padding: 8px 10px;
6456
+ border: 1px solid rgba(255, 255, 255, 0.18);
6457
+ border-radius: 6px;
6458
+ background: #18202e;
6459
+ color: #fff;
6460
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
6461
+ font: 500 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
6462
+ white-space: normal;
6463
+ overflow-wrap: anywhere;
6464
+ pointer-events: auto;
6465
+ direction: inherit;
6466
+ }
6467
+
6468
+ .selected-label-tooltip[hidden] {
6469
+ display: none;
6470
+ }
6373
6471
 
6374
6472
  .input-container {
6375
6473
  position: relative;
@@ -6418,6 +6516,7 @@ class EnhancedSelect extends HTMLElement {
6418
6516
  overflow-y: var(--select-input-overflow-y, hidden);
6419
6517
  scrollbar-width: thin;
6420
6518
  box-sizing: border-box;
6519
+ padding: var(--select-input-content-padding, revert-layer);
6421
6520
  }
6422
6521
 
6423
6522
  .input-container:hover {
@@ -6443,7 +6542,6 @@ class EnhancedSelect extends HTMLElement {
6443
6542
  align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
6444
6543
  overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
6445
6544
  overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
6446
- padding-inline-end: var(--select-multi-input-end-gap, 12px);
6447
6545
  }
6448
6546
 
6449
6547
  .input-container.input-container--multi .input-content .selection-badge {
@@ -6481,7 +6579,7 @@ class EnhancedSelect extends HTMLElement {
6481
6579
  overflow-y: hidden;
6482
6580
  overscroll-behavior-x: contain;
6483
6581
  overscroll-behavior-y: none;
6484
- padding-inline-end: 0;
6582
+ padding: var(--select-input-content-padding, 0);
6485
6583
  scroll-padding-inline-end: var(--select-multi-action-area-width, var(--select-arrow-width, 42px));
6486
6584
  }
6487
6585
 
@@ -6584,6 +6682,7 @@ class EnhancedSelect extends HTMLElement {
6584
6682
  bottom: 0;
6585
6683
  width: var(--select-arrow-width, var(--select-arrow-size, 42px));
6586
6684
  height: var(--select-arrow-height, var(--select-arrow-size, auto));
6685
+ padding: var(--select-dropdown-arrow-container-padding, 0);
6587
6686
  display: flex;
6588
6687
  align-items: center;
6589
6688
  justify-content: center;
@@ -7463,7 +7562,25 @@ class EnhancedSelect extends HTMLElement {
7463
7562
  this._shadow.appendChild(style);
7464
7563
  }
7465
7564
  }
7565
+ _isArrowOrClearControlEvent(event) {
7566
+ const path = event.composedPath();
7567
+ return ((this._arrowContainer != null && path.includes(this._arrowContainer)) ||
7568
+ (this._clearControl != null && path.includes(this._clearControl)));
7569
+ }
7466
7570
  _attachEventListeners() {
7571
+ this._shadow.addEventListener('pointerover', (event) => this._handleSelectedLabelPointerOver(event));
7572
+ this._shadow.addEventListener('pointerout', (event) => this._handleSelectedLabelPointerOut(event));
7573
+ this._shadow.addEventListener('focusin', (event) => this._handleSelectedLabelFocusIn(event));
7574
+ this._shadow.addEventListener('focusout', (event) => this._handleSelectedLabelFocusOut(event));
7575
+ this._shadow.addEventListener('keydown', (event) => {
7576
+ const keyboardEvent = event;
7577
+ if (keyboardEvent.key !== 'Escape' || this._selectedLabelTooltip.hidden)
7578
+ return;
7579
+ keyboardEvent.preventDefault();
7580
+ keyboardEvent.stopPropagation();
7581
+ this._dismissSelectedLabelTooltip();
7582
+ });
7583
+ this._inputContent.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, { passive: true });
7467
7584
  // Arrow click handler
7468
7585
  if (this._arrowContainer) {
7469
7586
  this._boundArrowClick = (e) => {
@@ -7499,13 +7616,11 @@ class EnhancedSelect extends HTMLElement {
7499
7616
  // Prevent propagation to document click listener but do NOT preventDefault.
7500
7617
  // Allow default so browser events (click) on newly opened options still fire.
7501
7618
  // 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.
7502
- const target = e.target;
7503
7619
  if (!this._config.enabled)
7504
7620
  return;
7505
- if (target && target.closest('.dropdown-arrow-container'))
7506
- return;
7507
- if (target && target.closest('.clear-control-button'))
7621
+ if (this._isArrowOrClearControlEvent(e))
7508
7622
  return;
7623
+ const target = e.target;
7509
7624
  if (this._isPointerOnInputScrollbar(e)) {
7510
7625
  this._suppressNextOpenClick = true;
7511
7626
  return;
@@ -7552,7 +7667,6 @@ class EnhancedSelect extends HTMLElement {
7552
7667
  }
7553
7668
  });
7554
7669
  this._inputContainer.addEventListener('click', (e) => {
7555
- const target = e.target;
7556
7670
  const isHorizontalMultiMode = this._config.selection.mode === 'multi'
7557
7671
  && (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal';
7558
7672
  if (!this._config.enabled || !isHorizontalMultiMode) {
@@ -7560,7 +7674,7 @@ class EnhancedSelect extends HTMLElement {
7560
7674
  this._multiScrollDrag.moved = false;
7561
7675
  return;
7562
7676
  }
7563
- if (target && target.closest('.dropdown-arrow-container, .clear-control-button')) {
7677
+ if (this._isArrowOrClearControlEvent(e)) {
7564
7678
  this._suppressNextOpenClick = false;
7565
7679
  this._multiScrollDrag.moved = false;
7566
7680
  return;
@@ -7635,6 +7749,10 @@ class EnhancedSelect extends HTMLElement {
7635
7749
  if (!this._config.searchable)
7636
7750
  return;
7637
7751
  const query = e.target.value;
7752
+ if (this._selectedLabelTooltipTrigger === this._input
7753
+ && this._getSelectedLabelForTrigger(this._input) === null) {
7754
+ this._hideSelectedLabelTooltip();
7755
+ }
7638
7756
  this._handleSearch(query);
7639
7757
  });
7640
7758
  // If the user presses down inside the options container we should
@@ -7797,6 +7915,286 @@ class EnhancedSelect extends HTMLElement {
7797
7915
  return index === undefined ? null : this._getOptionElementByIndex(index);
7798
7916
  },
7799
7917
  });
7918
+ this._syncSelectedLabelTooltipDescription();
7919
+ }
7920
+ _selectedLabelTriggerFromTarget(target) {
7921
+ if (!(target instanceof HTMLElement))
7922
+ return null;
7923
+ if (target === this._input)
7924
+ return target;
7925
+ const label = target.closest('.selection-badge-label');
7926
+ return label && this._inputContent.contains(label) ? label : null;
7927
+ }
7928
+ _getSelectedLabelForTrigger(trigger) {
7929
+ const entries = this._getSelectedEntries();
7930
+ if (trigger === this._input) {
7931
+ if (this._config.selection.mode !== 'single' || this._state.searchQuery.length > 0)
7932
+ return null;
7933
+ const item = entries[0]?.item;
7934
+ if (item === undefined)
7935
+ return null;
7936
+ const label = this._getItemLabel(item);
7937
+ return this._input.value === label ? label : null;
7938
+ }
7939
+ if (!trigger.classList.contains('selection-badge-label'))
7940
+ return null;
7941
+ const key = this._selectedLabelKeys.get(trigger);
7942
+ if (key === undefined)
7943
+ return null;
7944
+ const entry = entries.find((candidate) => candidate.key === key);
7945
+ if (!entry)
7946
+ return null;
7947
+ const label = this._getItemLabel(entry.item);
7948
+ return trigger.textContent === label ? label : null;
7949
+ }
7950
+ _isSelectedLabelTruncated(trigger) {
7951
+ if (!trigger.isConnected)
7952
+ return false;
7953
+ return trigger.clientWidth > 0 && trigger.scrollWidth > trigger.clientWidth + 1;
7954
+ }
7955
+ _handleSelectedLabelPointerOver(event) {
7956
+ const target = event.target;
7957
+ if (target?.closest('.selected-label-tooltip') === this._selectedLabelTooltip) {
7958
+ this._selectedLabelTooltipPointerInside = true;
7959
+ this._clearSelectedLabelTooltipHideTimer();
7960
+ return;
7961
+ }
7962
+ const trigger = this._selectedLabelTriggerFromTarget(target);
7963
+ if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
7964
+ return;
7965
+ this._selectedLabelTooltipPointerTrigger = trigger;
7966
+ this._selectedLabelTooltipDismissedTrigger = null;
7967
+ this._showSelectedLabelTooltip(trigger);
7968
+ }
7969
+ _handleSelectedLabelPointerOut(event) {
7970
+ const target = event.target;
7971
+ if (target === this._selectedLabelTooltip || this._selectedLabelTooltip.contains(target)) {
7972
+ if (event.relatedTarget instanceof Node && this._selectedLabelTooltip.contains(event.relatedTarget))
7973
+ return;
7974
+ this._selectedLabelTooltipPointerInside = false;
7975
+ this._scheduleSelectedLabelTooltipHide();
7976
+ return;
7977
+ }
7978
+ const trigger = this._selectedLabelTriggerFromTarget(target);
7979
+ if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
7980
+ return;
7981
+ if (this._selectedLabelTooltipPointerTrigger === trigger) {
7982
+ this._selectedLabelTooltipPointerTrigger = null;
7983
+ if (this._selectedLabelTooltipDismissedTrigger === trigger) {
7984
+ this._selectedLabelTooltipDismissedTrigger = null;
7985
+ }
7986
+ }
7987
+ if (event.relatedTarget === this._selectedLabelTooltip) {
7988
+ this._selectedLabelTooltipPointerInside = true;
7989
+ this._clearSelectedLabelTooltipHideTimer();
7990
+ return;
7991
+ }
7992
+ this._scheduleSelectedLabelTooltipHide();
7993
+ }
7994
+ _handleSelectedLabelFocusIn(event) {
7995
+ const trigger = this._selectedLabelTriggerFromTarget(event.target);
7996
+ if (!trigger)
7997
+ return;
7998
+ this._selectedLabelTooltipFocusTrigger = trigger;
7999
+ this._selectedLabelTooltipDismissedTrigger = null;
8000
+ this._showSelectedLabelTooltip(trigger);
8001
+ }
8002
+ _handleSelectedLabelFocusOut(event) {
8003
+ const trigger = this._selectedLabelTriggerFromTarget(event.target);
8004
+ if (!trigger || this._selectedLabelTooltipFocusTrigger !== trigger)
8005
+ return;
8006
+ this._selectedLabelTooltipFocusTrigger = null;
8007
+ if (this._selectedLabelTooltipDismissedTrigger === trigger) {
8008
+ this._selectedLabelTooltipDismissedTrigger = null;
8009
+ }
8010
+ this._scheduleSelectedLabelTooltipHide();
8011
+ }
8012
+ _showSelectedLabelTooltip(trigger) {
8013
+ if (this._selectedLabelTooltipDismissedTrigger === trigger)
8014
+ return;
8015
+ if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
8016
+ if (this._selectedLabelTooltipTrigger === trigger)
8017
+ this._hideSelectedLabelTooltip();
8018
+ return;
8019
+ }
8020
+ const label = this._getSelectedLabelForTrigger(trigger);
8021
+ if (label === null || !this._isSelectedLabelTruncated(trigger)) {
8022
+ if (trigger.classList.contains('selection-badge-label'))
8023
+ trigger.tabIndex = -1;
8024
+ if (this._selectedLabelTooltipTrigger === trigger)
8025
+ this._hideSelectedLabelTooltip();
8026
+ return;
8027
+ }
8028
+ if (trigger.classList.contains('selection-badge-label'))
8029
+ trigger.tabIndex = 0;
8030
+ if (this._selectedLabelTooltipTrigger !== trigger) {
8031
+ this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8032
+ this._selectedLabelTooltipTrigger = trigger;
8033
+ }
8034
+ this._selectedLabelTooltip.textContent = label;
8035
+ this._selectedLabelTooltip.hidden = false;
8036
+ this._positionSelectedLabelTooltip(trigger);
8037
+ this._syncSelectedLabelTooltipDescription();
8038
+ this._clearSelectedLabelTooltipHideTimer();
8039
+ }
8040
+ _positionSelectedLabelTooltip(trigger) {
8041
+ if (this._selectedLabelTooltip.hidden || !trigger.isConnected)
8042
+ return;
8043
+ const triggerRect = trigger.getBoundingClientRect();
8044
+ const tooltip = this._selectedLabelTooltip;
8045
+ tooltip.style.maxWidth = `min(24rem, calc(100vw - 16px))`;
8046
+ tooltip.style.direction = getComputedStyle(trigger).direction;
8047
+ const tooltipRect = tooltip.getBoundingClientRect();
8048
+ const viewportWidth = document.documentElement.clientWidth || window.innerWidth;
8049
+ const viewportHeight = document.documentElement.clientHeight || window.innerHeight;
8050
+ const rtl = getComputedStyle(trigger).direction === 'rtl';
8051
+ const desiredLeft = rtl ? triggerRect.right - tooltipRect.width : triggerRect.left;
8052
+ const left = Math.max(8, Math.min(desiredLeft, viewportWidth - tooltipRect.width - 8));
8053
+ const above = triggerRect.top - tooltipRect.height - 6;
8054
+ const top = above >= 8 ? above : Math.min(triggerRect.bottom + 6, viewportHeight - tooltipRect.height - 8);
8055
+ tooltip.style.left = `${left}px`;
8056
+ tooltip.style.top = `${Math.max(8, top)}px`;
8057
+ }
8058
+ _syncSelectedLabelTooltipDescription() {
8059
+ const trigger = this._selectedLabelTooltipTrigger;
8060
+ this._removeSelectedLabelTooltipDescription(trigger);
8061
+ if (trigger && !this._selectedLabelTooltip.hidden) {
8062
+ const ids = new Set((trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean));
8063
+ ids.add(this._selectedLabelTooltip.id);
8064
+ trigger.setAttribute('aria-describedby', [...ids].join(' '));
8065
+ }
8066
+ }
8067
+ _removeSelectedLabelTooltipDescription(trigger) {
8068
+ if (!trigger)
8069
+ return;
8070
+ const ids = (trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
8071
+ const remaining = ids.filter((id) => id !== this._selectedLabelTooltip.id);
8072
+ if (remaining.length)
8073
+ trigger.setAttribute('aria-describedby', remaining.join(' '));
8074
+ else
8075
+ trigger.removeAttribute('aria-describedby');
8076
+ }
8077
+ _dismissSelectedLabelTooltip() {
8078
+ this._selectedLabelTooltipDismissedTrigger = this._selectedLabelTooltipFocusTrigger
8079
+ ?? this._selectedLabelTooltipTrigger
8080
+ ?? this._selectedLabelTooltipPointerTrigger;
8081
+ this._hideSelectedLabelTooltip();
8082
+ }
8083
+ _hideSelectedLabelTooltip(clearInteractionState = false) {
8084
+ this._clearSelectedLabelTooltipHideTimer();
8085
+ this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
8086
+ this._selectedLabelTooltipTrigger = null;
8087
+ this._selectedLabelTooltip.hidden = true;
8088
+ if (clearInteractionState) {
8089
+ this._selectedLabelTooltipPointerTrigger = null;
8090
+ this._selectedLabelTooltipFocusTrigger = null;
8091
+ this._selectedLabelTooltipPointerInside = false;
8092
+ this._selectedLabelTooltipDismissedTrigger = null;
8093
+ }
8094
+ }
8095
+ _clearSelectedLabelTooltipHideTimer() {
8096
+ if (this._selectedLabelTooltipHideTimer === null)
8097
+ return;
8098
+ window.clearTimeout(this._selectedLabelTooltipHideTimer);
8099
+ this._lifecycleTimers.delete(this._selectedLabelTooltipHideTimer);
8100
+ this._selectedLabelTooltipHideTimer = null;
8101
+ }
8102
+ _scheduleSelectedLabelTooltipHide() {
8103
+ this._clearSelectedLabelTooltipHideTimer();
8104
+ this._selectedLabelTooltipHideTimer = this._setLifecycleTimeout(() => {
8105
+ this._selectedLabelTooltipHideTimer = null;
8106
+ if (this._selectedLabelTooltipPointerInside)
8107
+ return;
8108
+ const trigger = this._selectedLabelTooltipTrigger;
8109
+ if (trigger && (this._selectedLabelTooltipFocusTrigger === trigger
8110
+ || this._selectedLabelTooltipPointerTrigger === trigger))
8111
+ return;
8112
+ const focusedTrigger = this._selectedLabelTooltipFocusTrigger;
8113
+ if (focusedTrigger && focusedTrigger !== this._selectedLabelTooltipDismissedTrigger
8114
+ && focusedTrigger.isConnected
8115
+ && this._isSelectedLabelVisibleInViewport(focusedTrigger)) {
8116
+ this._showSelectedLabelTooltip(focusedTrigger);
8117
+ return;
8118
+ }
8119
+ this._hideSelectedLabelTooltip();
8120
+ }, 180);
8121
+ }
8122
+ _isSelectedLabelVisibleInViewport(trigger) {
8123
+ if (!trigger.classList.contains('selection-badge-label'))
8124
+ return true;
8125
+ const viewport = this._inputContent;
8126
+ const triggerRect = trigger.getBoundingClientRect();
8127
+ const viewportRect = viewport.getBoundingClientRect();
8128
+ // DOM-only test environments do not calculate layout rectangles. Leave
8129
+ // visibility indeterminate there; browser measurement handles real layout.
8130
+ if (triggerRect.width === 0 && triggerRect.height === 0
8131
+ && viewportRect.width === 0 && viewportRect.height === 0)
8132
+ return true;
8133
+ const left = viewportRect.left + viewport.clientLeft;
8134
+ const top = viewportRect.top + viewport.clientTop;
8135
+ const right = left + viewport.clientWidth;
8136
+ const bottom = top + viewport.clientHeight;
8137
+ return triggerRect.right > left && triggerRect.left < right
8138
+ && triggerRect.bottom > top && triggerRect.top < bottom;
8139
+ }
8140
+ _observeSelectedLabelTooltipTargets() {
8141
+ if (typeof ResizeObserver === 'undefined')
8142
+ return;
8143
+ const hasSingleSelection = this._config.selection.mode === 'single'
8144
+ && this._getSelectedEntries().length > 0;
8145
+ const chipLabels = this._getActiveChipBadges()
8146
+ .map((badge) => badge.querySelector('.selection-badge-label'))
8147
+ .filter((label) => label !== null);
8148
+ if (!hasSingleSelection && chipLabels.length === 0) {
8149
+ this._selectedLabelTooltipResizeObserver?.disconnect();
8150
+ this._selectedLabelTooltipResizeObserver = null;
8151
+ return;
8152
+ }
8153
+ if (!this._selectedLabelTooltipResizeObserver) {
8154
+ this._selectedLabelTooltipResizeObserver = new ResizeObserver(() => this._scheduleSelectedLabelTooltipMeasure());
8155
+ }
8156
+ this._selectedLabelTooltipResizeObserver.disconnect();
8157
+ if (hasSingleSelection)
8158
+ this._selectedLabelTooltipResizeObserver.observe(this._input);
8159
+ chipLabels.forEach((label) => {
8160
+ this._selectedLabelTooltipResizeObserver?.observe(label);
8161
+ });
8162
+ }
8163
+ _refreshSelectedLabelTooltipMeasurements() {
8164
+ this._getActiveChipBadges().forEach((badge) => {
8165
+ const label = badge.querySelector('.selection-badge-label');
8166
+ if (!label)
8167
+ return;
8168
+ label.tabIndex = this._isSelectedLabelTruncated(label) ? 0 : -1;
8169
+ });
8170
+ const currentTrigger = this._selectedLabelTooltipTrigger;
8171
+ if (currentTrigger?.classList.contains('selection-badge-label')
8172
+ && !this._isSelectedLabelVisibleInViewport(currentTrigger)) {
8173
+ if (this._selectedLabelTooltipPointerTrigger === currentTrigger) {
8174
+ this._selectedLabelTooltipPointerTrigger = null;
8175
+ }
8176
+ this._hideSelectedLabelTooltip();
8177
+ }
8178
+ const trigger = this._selectedLabelTooltipTrigger
8179
+ ?? this._selectedLabelTooltipFocusTrigger
8180
+ ?? this._selectedLabelTooltipPointerTrigger;
8181
+ if (!trigger)
8182
+ return;
8183
+ if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
8184
+ if (this._selectedLabelTooltipPointerTrigger === trigger) {
8185
+ this._selectedLabelTooltipPointerTrigger = null;
8186
+ }
8187
+ if (this._selectedLabelTooltipTrigger === trigger)
8188
+ this._hideSelectedLabelTooltip();
8189
+ return;
8190
+ }
8191
+ const label = this._getSelectedLabelForTrigger(trigger);
8192
+ if (label === null || !this._isSelectedLabelTruncated(trigger)) {
8193
+ if (this._selectedLabelTooltipTrigger === trigger)
8194
+ this._hideSelectedLabelTooltip();
8195
+ return;
8196
+ }
8197
+ this._showSelectedLabelTooltip(trigger);
7800
8198
  }
7801
8199
  _syncListboxAccessibility() {
7802
8200
  if (!this._dropdown || !this._engine || !this._state)
@@ -8393,6 +8791,10 @@ class EnhancedSelect extends HTMLElement {
8393
8791
  return results;
8394
8792
  }
8395
8793
  _handleSearch(query) {
8794
+ if (this._selectedLabelTooltipTrigger === this._input
8795
+ && (query.length > 0 || this._getSelectedLabelForTrigger(this._input) === null)) {
8796
+ this._hideSelectedLabelTooltip();
8797
+ }
8396
8798
  if (this._dataRequestCoordinator
8397
8799
  && (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)) {
8398
8800
  // Keep the committed query/generation stable until the accepted snapshot
@@ -8497,6 +8899,12 @@ class EnhancedSelect extends HTMLElement {
8497
8899
  }
8498
8900
  }
8499
8901
  _handleKeydown(e) {
8902
+ if (e.key === 'Escape' && !this._selectedLabelTooltip.hidden) {
8903
+ e.preventDefault();
8904
+ e.stopPropagation();
8905
+ this._dismissSelectedLabelTooltip();
8906
+ return;
8907
+ }
8500
8908
  if (!this._config.enabled)
8501
8909
  return;
8502
8910
  switch (e.key) {
@@ -8570,6 +8978,9 @@ class EnhancedSelect extends HTMLElement {
8570
8978
  break;
8571
8979
  case 'Enter':
8572
8980
  case ' ':
8981
+ if (e.key === ' ' && this._config.searchable && e.target === this._input) {
8982
+ break;
8983
+ }
8573
8984
  e.preventDefault();
8574
8985
  if (!this._state.isOpen) {
8575
8986
  this._handleOpen();
@@ -8593,7 +9004,8 @@ class EnhancedSelect extends HTMLElement {
8593
9004
  break;
8594
9005
  case 'a':
8595
9006
  case 'A':
8596
- if ((e.ctrlKey || e.metaKey) && this._config.selection.mode === 'multi') {
9007
+ if ((e.ctrlKey || e.metaKey) && !e.altKey
9008
+ && this._config.selection.mode === 'multi' && !this._config.searchable) {
8597
9009
  e.preventDefault();
8598
9010
  this._selectAll();
8599
9011
  }
@@ -9064,7 +9476,7 @@ class EnhancedSelect extends HTMLElement {
9064
9476
  : null;
9065
9477
  const hadFocusedChipRemove = focusedBadge !== null;
9066
9478
  const focusedBadgeIndex = focusedBadge
9067
- ? Array.from(this._inputContent.querySelectorAll('.selection-badge')).indexOf(focusedBadge)
9479
+ ? this._getActiveChipBadges().indexOf(focusedBadge)
9068
9480
  : -1;
9069
9481
  const option = this._itemRegistry.keyToRecord.has(entry.key)
9070
9482
  ? this._getOptionElementByIndex(entry.index)
@@ -9090,7 +9502,7 @@ class EnhancedSelect extends HTMLElement {
9090
9502
  this._renderOptions();
9091
9503
  this._emitChange();
9092
9504
  if (hadFocusedChipRemove && this.isConnected) {
9093
- const removeButtons = this._inputContent.querySelectorAll('[part="chip-remove"]');
9505
+ const removeButtons = this._getActiveChipRemoveButtons();
9094
9506
  if (removeButtons.length > 0) {
9095
9507
  const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9096
9508
  removeButtons[nextFocusIndex].focus();
@@ -9104,8 +9516,248 @@ class EnhancedSelect extends HTMLElement {
9104
9516
  : undefined;
9105
9517
  this._emit('remove', { item: config?.item ?? item, index: entry.index });
9106
9518
  }
9519
+ _getActiveChipBadges() {
9520
+ return Array.from(this._inputContent.querySelectorAll('.selection-badge'))
9521
+ .filter((badge) => badge.dataset.motion !== 'exiting' && !badge.hasAttribute('inert'));
9522
+ }
9523
+ _getActiveChipRemoveButtons() {
9524
+ return this._getActiveChipBadges()
9525
+ .map((badge) => badge.querySelector('[part="chip-remove"]'))
9526
+ .filter((button) => button !== null && !button.disabled);
9527
+ }
9528
+ _clearChipPresentation() {
9529
+ const badges = new Set(this._chipElements.values());
9530
+ const tooltipTriggers = [
9531
+ this._selectedLabelTooltipTrigger,
9532
+ this._selectedLabelTooltipPointerTrigger,
9533
+ this._selectedLabelTooltipFocusTrigger,
9534
+ this._selectedLabelTooltipDismissedTrigger,
9535
+ ];
9536
+ if (tooltipTriggers.some((trigger) => trigger !== null
9537
+ && Array.from(badges).some((badge) => badge.contains(trigger)))) {
9538
+ this._hideSelectedLabelTooltip(true);
9539
+ }
9540
+ for (const [key, state] of this._chipExitStates) {
9541
+ window.clearTimeout(state.timer);
9542
+ this._chipExitStates.delete(key);
9543
+ state.animations.forEach((animation) => animation.cancel());
9544
+ }
9545
+ for (const badge of this._chipElements.values()) {
9546
+ badge.removeAttribute('inert');
9547
+ badge.remove();
9548
+ }
9549
+ this._chipExitStates.clear();
9550
+ this._chipElements.clear();
9551
+ }
9552
+ _cancelChipExit(key, badge) {
9553
+ const state = this._chipExitStates.get(key);
9554
+ if (!state || state.badge !== badge)
9555
+ return;
9556
+ window.clearTimeout(state.timer);
9557
+ this._chipExitStates.delete(key);
9558
+ state.animations.forEach((animation) => animation.cancel());
9559
+ badge.removeAttribute('data-motion');
9560
+ badge.removeAttribute('aria-hidden');
9561
+ badge.removeAttribute('inert');
9562
+ badge.setAttribute('part', 'chip');
9563
+ const removeButton = badge.querySelector('[part="chip-remove"]');
9564
+ if (removeButton)
9565
+ removeButton.disabled = false;
9566
+ }
9567
+ _finishChipExit(key, expected) {
9568
+ const state = this._chipExitStates.get(key);
9569
+ if (!state || state.badge !== expected)
9570
+ return;
9571
+ window.clearTimeout(state.timer);
9572
+ this._chipExitStates.delete(key);
9573
+ state.animations.forEach((animation) => {
9574
+ if (animation.playState !== 'finished')
9575
+ animation.cancel();
9576
+ });
9577
+ this._chipElements.delete(key);
9578
+ expected.remove();
9579
+ if (this.isConnected) {
9580
+ this._observeSelectedLabelTooltipTargets();
9581
+ this._refreshSelectedLabelTooltipMeasurements();
9582
+ }
9583
+ }
9584
+ _moveFocusOutOfChip(badge) {
9585
+ const activeElement = this._shadow.activeElement;
9586
+ if (!(activeElement instanceof HTMLElement) || !badge.contains(activeElement))
9587
+ return;
9588
+ const badges = this._getActiveChipBadges().filter((candidate) => candidate !== badge);
9589
+ const oldIndex = Array.from(this._inputContent.querySelectorAll('.selection-badge')).indexOf(badge);
9590
+ const buttons = badges
9591
+ .map((candidate) => candidate.querySelector('[part="chip-remove"]'))
9592
+ .filter((button) => button !== null && !button.disabled);
9593
+ const next = buttons[Math.min(Math.max(oldIndex, 0), buttons.length - 1)];
9594
+ if (next)
9595
+ next.focus({ preventScroll: true });
9596
+ else
9597
+ this._input.focus({ preventScroll: true });
9598
+ }
9599
+ _beginChipExit(key, badge) {
9600
+ if (this._chipExitStates.has(key))
9601
+ return;
9602
+ this._moveFocusOutOfChip(badge);
9603
+ const label = badge.querySelector('.selection-badge-label');
9604
+ if (label) {
9605
+ this._removeSelectedLabelTooltipDescription(label);
9606
+ label.tabIndex = -1;
9607
+ if (this._selectedLabelTooltipPointerTrigger === label)
9608
+ this._selectedLabelTooltipPointerTrigger = null;
9609
+ if (this._selectedLabelTooltipFocusTrigger === label)
9610
+ this._selectedLabelTooltipFocusTrigger = null;
9611
+ if (this._selectedLabelTooltipDismissedTrigger === label)
9612
+ this._selectedLabelTooltipDismissedTrigger = null;
9613
+ if (this._selectedLabelTooltipTrigger === label)
9614
+ this._hideSelectedLabelTooltip();
9615
+ }
9616
+ badge.dataset.motion = 'exiting';
9617
+ badge.setAttribute('aria-hidden', 'true');
9618
+ badge.setAttribute('inert', '');
9619
+ badge.setAttribute('part', 'chip-exiting');
9620
+ const removeButton = badge.querySelector('[part="chip-remove"]');
9621
+ if (removeButton)
9622
+ removeButton.disabled = true;
9623
+ // Force style resolution after the exiting part is exposed. This also
9624
+ // verifies that a consumer keyframe is actually available across Shadow DOM.
9625
+ badge.getBoundingClientRect();
9626
+ const animations = (typeof badge.getAnimations === 'function' ? badge.getAnimations() : []).filter((animation) => {
9627
+ const cssAnimation = animation;
9628
+ return typeof cssAnimation.animationName === 'string'
9629
+ && cssAnimation.animationName !== 'none'
9630
+ && animation.playState !== 'idle';
9631
+ });
9632
+ const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
9633
+ if (reducedMotion || animations.length === 0) {
9634
+ badge.removeAttribute('data-motion');
9635
+ this._chipExitStates.set(key, { badge, animations: [], timer: 0 });
9636
+ this._finishChipExit(key, badge);
9637
+ return;
9638
+ }
9639
+ const endTimes = animations.map((animation) => Number(animation.effect?.getComputedTiming().endTime ?? 0));
9640
+ const maxEndTime = Math.max(0, ...endTimes);
9641
+ const fallbackDelay = Math.min(Number.isFinite(maxEndTime) ? maxEndTime + 100 : 1000, 5000);
9642
+ const timer = window.setTimeout(() => this._finishChipExit(key, badge), fallbackDelay);
9643
+ this._chipExitStates.set(key, { badge, animations, timer });
9644
+ void Promise.allSettled(animations.map((animation) => animation.finished))
9645
+ .then(() => this._finishChipExit(key, badge));
9646
+ }
9647
+ _createChip(key) {
9648
+ const badge = document.createElement('span');
9649
+ badge.className = 'selection-badge';
9650
+ badge.setAttribute('part', 'chip');
9651
+ const label = document.createElement('span');
9652
+ label.className = 'selection-badge-label';
9653
+ label.setAttribute('part', 'chip-label');
9654
+ this._selectedLabelKeys.set(label, key);
9655
+ badge.appendChild(label);
9656
+ this._chipElements.set(key, badge);
9657
+ return badge;
9658
+ }
9659
+ _updateChip(key, index, item, badge) {
9660
+ const getLabel = this._config.serverSide.getLabelFromItem || ((value) => value?.label ?? String(value));
9661
+ const labelText = getLabel(item);
9662
+ badge.className = 'selection-badge';
9663
+ if (this._config.styles.classNames?.badge) {
9664
+ badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
9665
+ }
9666
+ badge.setAttribute('part', 'chip');
9667
+ badge.removeAttribute('aria-hidden');
9668
+ badge.removeAttribute('inert');
9669
+ badge.removeAttribute('data-motion');
9670
+ const label = badge.querySelector('.selection-badge-label');
9671
+ label.className = 'selection-badge-label';
9672
+ if (this._config.styles.classNames?.badgeLabel) {
9673
+ label.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
9674
+ }
9675
+ label.textContent = labelText;
9676
+ this._selectedLabelKeys.set(label, key);
9677
+ const shouldShowRemove = this._config.selection.showRemoveButton !== false;
9678
+ let removeButton = badge.querySelector('[part="chip-remove"]');
9679
+ if (!shouldShowRemove) {
9680
+ removeButton?.remove();
9681
+ return;
9682
+ }
9683
+ if (!removeButton) {
9684
+ removeButton = document.createElement('button');
9685
+ removeButton.type = 'button';
9686
+ removeButton.addEventListener('pointerdown', (event) => {
9687
+ event.stopPropagation();
9688
+ event.preventDefault();
9689
+ });
9690
+ removeButton.addEventListener('click', (event) => {
9691
+ event.stopPropagation();
9692
+ event.preventDefault();
9693
+ this._handleOptionRemove(index, key);
9694
+ });
9695
+ const removeIcon = document.createElement('span');
9696
+ removeIcon.className = 'badge-remove-icon';
9697
+ removeIcon.setAttribute('part', 'chip-remove-icon');
9698
+ removeButton.appendChild(removeIcon);
9699
+ badge.appendChild(removeButton);
9700
+ }
9701
+ removeButton.className = 'badge-remove';
9702
+ if (this._config.styles.classNames?.removeButton) {
9703
+ removeButton.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
9704
+ }
9705
+ if (this._config.styles.classNames?.badgeRemove) {
9706
+ removeButton.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
9707
+ }
9708
+ removeButton.setAttribute('part', 'chip-remove');
9709
+ removeButton.setAttribute('aria-label', `Remove ${labelText}`);
9710
+ removeButton.disabled = false;
9711
+ const removeIcon = removeButton.querySelector('[part="chip-remove-icon"]');
9712
+ removeIcon.className = 'badge-remove-icon';
9713
+ if (this._config.styles.classNames?.badgeRemoveIcon) {
9714
+ removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
9715
+ }
9716
+ this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
9717
+ }
9718
+ _renderSelectedChips(entries) {
9719
+ const selectedKeys = new Set(entries.map(({ key }) => key));
9720
+ for (const { key, index, item } of entries) {
9721
+ let badge = this._chipElements.get(key);
9722
+ if (!badge)
9723
+ badge = this._createChip(key);
9724
+ this._cancelChipExit(key, badge);
9725
+ this._updateChip(key, index, item, badge);
9726
+ }
9727
+ for (const [key, badge] of this._chipElements) {
9728
+ if (!selectedKeys.has(key))
9729
+ this._beginChipExit(key, badge);
9730
+ }
9731
+ // Do not move chips merely because another chip entered its exit period.
9732
+ // That keeps the exiting chip in its original layout slot while the active
9733
+ // sequence remains correct. Reorder only when selected-key order changed.
9734
+ const desiredBadges = entries
9735
+ .map(({ key }) => this._chipElements.get(key))
9736
+ .filter((badge) => badge !== undefined);
9737
+ const currentBadges = this._getActiveChipBadges();
9738
+ const orderChanged = desiredBadges.length !== currentBadges.length
9739
+ || desiredBadges.some((badge, index) => badge !== currentBadges[index]);
9740
+ if (orderChanged) {
9741
+ let nextSibling = this._input;
9742
+ for (let index = desiredBadges.length - 1; index >= 0; index -= 1) {
9743
+ const badge = desiredBadges[index];
9744
+ if (badge.nextSibling !== nextSibling)
9745
+ this._inputContent.insertBefore(badge, nextSibling);
9746
+ nextSibling = badge;
9747
+ }
9748
+ }
9749
+ }
9107
9750
  _updateInputDisplay() {
9108
9751
  const selectedEntries = this._getSelectedEntries();
9752
+ const focusedElement = this._shadow.activeElement;
9753
+ const focusedSelectedKey = focusedElement?.classList.contains('selection-badge-label')
9754
+ ? this._selectedLabelKeys.get(focusedElement) ?? null
9755
+ : null;
9756
+ const focusedBadge = focusedElement?.closest('.selection-badge');
9757
+ const focusedChipKey = focusedBadge
9758
+ ? Array.from(this._chipElements.entries()).find(([, badge]) => badge === focusedBadge)?.[0] ?? null
9759
+ : null;
9760
+ const focusedBadgeIndex = focusedBadge ? this._getActiveChipBadges().indexOf(focusedBadge) : -1;
9109
9761
  const selectedItems = selectedEntries.map(({ item }) => item);
9110
9762
  const nextKeys = new Set(selectedEntries.map(({ key }) => key));
9111
9763
  const previousKeys = this._lastRenderedChipKeys;
@@ -9121,73 +9773,27 @@ class EnhancedSelect extends HTMLElement {
9121
9773
  // Only a newly added selected key can initiate auto-scroll.
9122
9774
  this._cancelLatestChipScroll();
9123
9775
  const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
9124
- if (selectedItems.length === 0) {
9125
- this._input.value = '';
9126
- this._input.placeholder = this._config.placeholder || 'Select an option...';
9127
- // Clear any badges
9128
- const existingBadges = this._inputContent.querySelectorAll('.selection-badge');
9129
- existingBadges.forEach(badge => badge.remove());
9130
- }
9131
- else if (this._config.selection.mode === 'single') {
9132
- this._input.value = getLabel(selectedItems[0]);
9776
+ if (this._config.selection.mode === 'multi') {
9777
+ if (selectedItems.length === 0) {
9778
+ this._input.value = '';
9779
+ this._input.placeholder = this._config.placeholder || 'Select an option...';
9780
+ }
9781
+ else {
9782
+ this._input.value = '';
9783
+ this._input.placeholder = '';
9784
+ }
9785
+ this._renderSelectedChips(selectedEntries);
9133
9786
  }
9134
9787
  else {
9135
- // Multi-select: show badges instead of text in input
9136
- this._input.value = '';
9137
- this._input.placeholder = '';
9138
- // Clear existing badges
9139
- const existingBadges = this._inputContent.querySelectorAll('.selection-badge');
9140
- existingBadges.forEach(badge => badge.remove());
9141
- // Create badges for each selected item
9142
- selectedEntries.forEach(({ key, index, item }) => {
9143
- const badge = document.createElement('span');
9144
- badge.className = 'selection-badge';
9145
- if (this._config.styles.classNames?.badge) {
9146
- badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
9147
- }
9148
- badge.setAttribute('part', 'chip');
9149
- const badgeLabel = document.createElement('span');
9150
- badgeLabel.className = 'selection-badge-label';
9151
- if (this._config.styles.classNames?.badgeLabel) {
9152
- badgeLabel.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
9153
- }
9154
- badgeLabel.setAttribute('part', 'chip-label');
9155
- badgeLabel.textContent = getLabel(item);
9156
- badge.appendChild(badgeLabel);
9157
- // Add remove button to badge
9158
- if (this._config.selection.showRemoveButton !== false) {
9159
- const removeBtn = document.createElement('button');
9160
- removeBtn.type = 'button';
9161
- removeBtn.className = 'badge-remove';
9162
- if (this._config.styles.classNames?.removeButton) {
9163
- removeBtn.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
9164
- }
9165
- if (this._config.styles.classNames?.badgeRemove) {
9166
- removeBtn.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
9167
- }
9168
- removeBtn.setAttribute('part', 'chip-remove');
9169
- removeBtn.setAttribute('aria-label', `Remove ${getLabel(item)}`);
9170
- const removeIcon = document.createElement('span');
9171
- removeIcon.className = 'badge-remove-icon';
9172
- if (this._config.styles.classNames?.badgeRemoveIcon) {
9173
- removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
9174
- }
9175
- removeIcon.setAttribute('part', 'chip-remove-icon');
9176
- this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
9177
- removeBtn.appendChild(removeIcon);
9178
- removeBtn.addEventListener('pointerdown', (e) => {
9179
- e.stopPropagation();
9180
- e.preventDefault();
9181
- });
9182
- removeBtn.addEventListener('click', (e) => {
9183
- e.stopPropagation();
9184
- e.preventDefault();
9185
- this._handleOptionRemove(index, key);
9186
- });
9187
- badge.appendChild(removeBtn);
9188
- }
9189
- this._inputContent.insertBefore(badge, this._input);
9190
- });
9788
+ // A mode switch ends visual exits immediately; a single-select has no chip presentation.
9789
+ this._clearChipPresentation();
9790
+ if (selectedItems.length === 0) {
9791
+ this._input.value = '';
9792
+ this._input.placeholder = this._config.placeholder || 'Select an option...';
9793
+ }
9794
+ else {
9795
+ this._input.value = getLabel(selectedItems[0]);
9796
+ }
9191
9797
  }
9192
9798
  // A query typed during an accepted-snapshot projection is a pending user
9193
9799
  // intent, not part of the committed projection state. Keep it visible even
@@ -9195,14 +9801,60 @@ class EnhancedSelect extends HTMLElement {
9195
9801
  if (this._acknowledgedPendingSearchQuery !== null) {
9196
9802
  this._input.value = this._acknowledgedPendingSearchQuery;
9197
9803
  }
9198
- // Recreating the chip DOM must not reset manual scrolling. In particular,
9199
- // remove/clear, config rerenders, and item refreshes are not scroll intents.
9804
+ // Preserve manual scrolling. Only a newly selected key can request auto-scroll.
9200
9805
  if (this._config.selection.mode === 'multi') {
9201
9806
  this._inputContent.scrollLeft = previousChipScrollLeft;
9202
9807
  if (newlyAddedKey !== undefined)
9203
9808
  this._scheduleLatestChipScroll(newlyAddedKey);
9204
9809
  }
9205
9810
  this._syncClearControlState();
9811
+ this._observeSelectedLabelTooltipTargets();
9812
+ this._refreshSelectedLabelTooltipMeasurements();
9813
+ if (focusedChipKey !== null && !nextKeys.has(focusedChipKey)) {
9814
+ const removeButtons = this._getActiveChipRemoveButtons();
9815
+ if (removeButtons.length > 0) {
9816
+ const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9817
+ removeButtons[nextFocusIndex].focus({ preventScroll: true });
9818
+ }
9819
+ else {
9820
+ this._input.focus({ preventScroll: true });
9821
+ }
9822
+ }
9823
+ else if (focusedChipKey !== null && focusedElement && !focusedElement.isConnected) {
9824
+ const badge = this._chipElements.get(focusedChipKey);
9825
+ const removeButton = badge?.querySelector('[part="chip-remove"]');
9826
+ if (removeButton && !removeButton.disabled)
9827
+ removeButton.focus({ preventScroll: true });
9828
+ else
9829
+ this._input.focus({ preventScroll: true });
9830
+ }
9831
+ else if (focusedSelectedKey !== null) {
9832
+ const replacement = this._getActiveChipBadges()
9833
+ .map((badge) => badge.querySelector('.selection-badge-label'))
9834
+ .find((label) => label && this._selectedLabelKeys.get(label) === focusedSelectedKey);
9835
+ if (!replacement) {
9836
+ const removeButtons = this._getActiveChipRemoveButtons();
9837
+ if (removeButtons.length > 0) {
9838
+ const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
9839
+ removeButtons[nextFocusIndex].focus({ preventScroll: true });
9840
+ }
9841
+ else {
9842
+ this._input.focus({ preventScroll: true });
9843
+ }
9844
+ }
9845
+ else if (this._isSelectedLabelTruncated(replacement)) {
9846
+ // The measurement pass assigns the tab stop before focus restoration.
9847
+ replacement.tabIndex = 0;
9848
+ replacement.focus({ preventScroll: true });
9849
+ }
9850
+ else {
9851
+ this._input.focus({ preventScroll: true });
9852
+ }
9853
+ }
9854
+ if (this._selectedLabelTooltipFocusTrigger === this._input
9855
+ || this._selectedLabelTooltipPointerTrigger === this._input) {
9856
+ this._showSelectedLabelTooltip(this._input);
9857
+ }
9206
9858
  }
9207
9859
  _cancelLatestChipScroll() {
9208
9860
  this._latestChipScrollGeneration += 1;
@@ -9234,7 +9886,7 @@ class EnhancedSelect extends HTMLElement {
9234
9886
  const index = entries.findIndex((entry) => entry.key === key);
9235
9887
  if (index < 0)
9236
9888
  return;
9237
- const chip = this._inputContent.querySelectorAll('.selection-badge')[index];
9889
+ const chip = this._getActiveChipBadges()[index];
9238
9890
  if (!chip)
9239
9891
  return;
9240
9892
  const hostBounds = this._inputContent.getBoundingClientRect();