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