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