@smilodon/core 1.19.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/README.md +104 -5
- package/dist/index.cjs +1539 -189
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1537 -190
- 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 +1539 -189
- 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 +72 -1
- package/dist/types/src/config/global-config.d.ts +21 -3
- package/dist/types/src/config/public-config.d.ts +21 -0
- package/dist/types/src/data-loading/public-types.d.ts +4 -2
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/native-types.d.ts +1 -1
- package/dist/types/src/utils/selected-options-projection.d.ts +18 -0
- package/dist/types/src/utils/selected-target-resolver.d.ts +2 -0
- package/dist/types/src/utils/visual-navigation.d.ts +15 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2072,6 +2072,123 @@ if (!customElements.get("smilodon-select")) {
|
|
|
2072
2072
|
customElements.define("smilodon-select", NativeSelectElement);
|
|
2073
2073
|
}
|
|
2074
2074
|
|
|
2075
|
+
const SELECTED_OPTIONS_FIELDS = new Set(['placement', 'groupedPlacement']);
|
|
2076
|
+
const SCROLL_TO_SELECTED_FIELDS = new Set([
|
|
2077
|
+
'enabled',
|
|
2078
|
+
'multiSelectTarget',
|
|
2079
|
+
'onOpen',
|
|
2080
|
+
'behavior',
|
|
2081
|
+
'block',
|
|
2082
|
+
]);
|
|
2083
|
+
const placements = new Set(['original', 'selected-first']);
|
|
2084
|
+
const groupedPlacements = new Set(['within-group']);
|
|
2085
|
+
const scrollTargets = new Set(['first', 'last']);
|
|
2086
|
+
const openPolicies = new Set(['preserve', 'reveal', 'align']);
|
|
2087
|
+
const scrollBehaviors = new Set(['auto', 'instant', 'smooth']);
|
|
2088
|
+
const scrollBlocks = new Set(['start', 'center', 'end', 'nearest']);
|
|
2089
|
+
function asPlainRecord(value) {
|
|
2090
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
2091
|
+
return null;
|
|
2092
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2093
|
+
return prototype === Object.prototype || prototype === null ? value : null;
|
|
2094
|
+
}
|
|
2095
|
+
function unknownFieldIssues(record, allowed) {
|
|
2096
|
+
return Object.keys(record)
|
|
2097
|
+
.filter((key) => !allowed.has(key))
|
|
2098
|
+
.sort()
|
|
2099
|
+
.map((key) => ({
|
|
2100
|
+
path: key,
|
|
2101
|
+
code: 'unknown-field',
|
|
2102
|
+
message: `Unknown configuration field: ${key}.`,
|
|
2103
|
+
}));
|
|
2104
|
+
}
|
|
2105
|
+
function validateEnum(record, field, allowed, issues) {
|
|
2106
|
+
const value = record[field];
|
|
2107
|
+
if (value === undefined)
|
|
2108
|
+
return;
|
|
2109
|
+
if (typeof value !== 'string') {
|
|
2110
|
+
issues.push({ path: field, code: 'invalid-type', message: `${field} must be a string.` });
|
|
2111
|
+
}
|
|
2112
|
+
else if (!allowed.has(value)) {
|
|
2113
|
+
issues.push({ path: field, code: 'invalid-value', message: `${field} has an unsupported value.` });
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
/** Validate a partial selected-options configuration update. */
|
|
2117
|
+
function validateSelectedOptionsConfig(candidate) {
|
|
2118
|
+
const record = asPlainRecord(candidate);
|
|
2119
|
+
if (!record) {
|
|
2120
|
+
return {
|
|
2121
|
+
valid: false,
|
|
2122
|
+
issues: [{ path: 'selectedOptions', code: 'invalid-type', message: 'selectedOptions must be a plain object.' }],
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
const issues = unknownFieldIssues(record, SELECTED_OPTIONS_FIELDS);
|
|
2126
|
+
validateEnum(record, 'placement', placements, issues);
|
|
2127
|
+
validateEnum(record, 'groupedPlacement', groupedPlacements, issues);
|
|
2128
|
+
if (issues.length > 0)
|
|
2129
|
+
return { valid: false, issues };
|
|
2130
|
+
return {
|
|
2131
|
+
valid: true,
|
|
2132
|
+
value: {
|
|
2133
|
+
...(record.placement === undefined ? {} : { placement: record.placement }),
|
|
2134
|
+
...(record.groupedPlacement === undefined
|
|
2135
|
+
? {}
|
|
2136
|
+
: { groupedPlacement: record.groupedPlacement }),
|
|
2137
|
+
},
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
/** Validate a partial scroll-to-selected configuration update. */
|
|
2141
|
+
function validateScrollToSelectedConfig(candidate) {
|
|
2142
|
+
const record = asPlainRecord(candidate);
|
|
2143
|
+
if (!record) {
|
|
2144
|
+
return {
|
|
2145
|
+
valid: false,
|
|
2146
|
+
issues: [{ path: 'scrollToSelected', code: 'invalid-type', message: 'scrollToSelected must be a plain object.' }],
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
const issues = unknownFieldIssues(record, SCROLL_TO_SELECTED_FIELDS);
|
|
2150
|
+
if (record.enabled !== undefined && typeof record.enabled !== 'boolean') {
|
|
2151
|
+
issues.push({ path: 'enabled', code: 'invalid-type', message: 'enabled must be a boolean.' });
|
|
2152
|
+
}
|
|
2153
|
+
validateEnum(record, 'multiSelectTarget', scrollTargets, issues);
|
|
2154
|
+
validateEnum(record, 'onOpen', openPolicies, issues);
|
|
2155
|
+
validateEnum(record, 'behavior', scrollBehaviors, issues);
|
|
2156
|
+
validateEnum(record, 'block', scrollBlocks, issues);
|
|
2157
|
+
if (issues.length > 0)
|
|
2158
|
+
return { valid: false, issues };
|
|
2159
|
+
return {
|
|
2160
|
+
valid: true,
|
|
2161
|
+
value: {
|
|
2162
|
+
...(record.enabled === undefined ? {} : { enabled: record.enabled }),
|
|
2163
|
+
...(record.multiSelectTarget === undefined
|
|
2164
|
+
? {}
|
|
2165
|
+
: { multiSelectTarget: record.multiSelectTarget }),
|
|
2166
|
+
...(record.onOpen === undefined ? {} : { onOpen: record.onOpen }),
|
|
2167
|
+
...(record.behavior === undefined ? {} : { behavior: record.behavior }),
|
|
2168
|
+
...(record.block === undefined ? {} : { block: record.block }),
|
|
2169
|
+
},
|
|
2170
|
+
};
|
|
2171
|
+
}
|
|
2172
|
+
/** Validate and copy only the new public configuration sections. */
|
|
2173
|
+
function validateSelectedOptionsConfigUpdate(config) {
|
|
2174
|
+
const result = { ...config };
|
|
2175
|
+
if (config.selectedOptions !== undefined) {
|
|
2176
|
+
const validation = validateSelectedOptionsConfig(config.selectedOptions);
|
|
2177
|
+
if (validation.valid)
|
|
2178
|
+
result.selectedOptions = validation.value;
|
|
2179
|
+
else
|
|
2180
|
+
delete result.selectedOptions;
|
|
2181
|
+
}
|
|
2182
|
+
if (config.scrollToSelected !== undefined) {
|
|
2183
|
+
const validation = validateScrollToSelectedConfig(config.scrollToSelected);
|
|
2184
|
+
if (validation.valid)
|
|
2185
|
+
result.scrollToSelected = validation.value;
|
|
2186
|
+
else
|
|
2187
|
+
delete result.scrollToSelected;
|
|
2188
|
+
}
|
|
2189
|
+
return result;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2075
2192
|
/**
|
|
2076
2193
|
* Global Configuration System for Select Components
|
|
2077
2194
|
* Allows users to define default behaviors that can be overridden at component level
|
|
@@ -2111,9 +2228,14 @@ const defaultConfig = {
|
|
|
2111
2228
|
scrollToSelected: {
|
|
2112
2229
|
enabled: true,
|
|
2113
2230
|
multiSelectTarget: 'first',
|
|
2231
|
+
onOpen: 'reveal',
|
|
2114
2232
|
behavior: 'smooth',
|
|
2115
2233
|
block: 'nearest',
|
|
2116
2234
|
},
|
|
2235
|
+
selectedOptions: {
|
|
2236
|
+
placement: 'original',
|
|
2237
|
+
groupedPlacement: 'within-group',
|
|
2238
|
+
},
|
|
2117
2239
|
loadMore: {
|
|
2118
2240
|
enabled: false,
|
|
2119
2241
|
itemsPerLoad: 3,
|
|
@@ -2196,7 +2318,8 @@ class SelectConfigManager {
|
|
|
2196
2318
|
* Update global configuration (deep merge)
|
|
2197
2319
|
*/
|
|
2198
2320
|
updateConfig(updates) {
|
|
2199
|
-
|
|
2321
|
+
const acceptedUpdates = validateSelectedOptionsConfigUpdate(updates);
|
|
2322
|
+
this.config = this.deepMerge(this.config, acceptedUpdates);
|
|
2200
2323
|
}
|
|
2201
2324
|
/**
|
|
2202
2325
|
* Reset to default configuration
|
|
@@ -3157,6 +3280,94 @@ function arraysEqualByValue(a, b) {
|
|
|
3157
3280
|
return true;
|
|
3158
3281
|
}
|
|
3159
3282
|
|
|
3283
|
+
function createVisualNavigationModel(orderedKeys, isSelectable) {
|
|
3284
|
+
const ordered = [...orderedKeys];
|
|
3285
|
+
const selectableKeys = [];
|
|
3286
|
+
const positionByKey = new Map();
|
|
3287
|
+
const selectablePositionByKey = new Map();
|
|
3288
|
+
ordered.forEach((key, position) => {
|
|
3289
|
+
positionByKey.set(key, position);
|
|
3290
|
+
if (isSelectable(key)) {
|
|
3291
|
+
selectablePositionByKey.set(key, selectableKeys.length);
|
|
3292
|
+
selectableKeys.push(key);
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3295
|
+
return { orderedKeys: ordered, selectableKeys, positionByKey, selectablePositionByKey };
|
|
3296
|
+
}
|
|
3297
|
+
/** Resolve a clamped keyboard movement in visual order. */
|
|
3298
|
+
function resolveVisualMovement(model, currentKey, delta) {
|
|
3299
|
+
const { selectableKeys, selectablePositionByKey } = model;
|
|
3300
|
+
if (selectableKeys.length === 0)
|
|
3301
|
+
return null;
|
|
3302
|
+
const currentPosition = currentKey === null ? undefined : selectablePositionByKey.get(currentKey);
|
|
3303
|
+
const basePosition = currentPosition ?? (delta >= 0 ? -1 : selectableKeys.length);
|
|
3304
|
+
const nextPosition = Math.max(0, Math.min(selectableKeys.length - 1, basePosition + delta));
|
|
3305
|
+
return selectableKeys[nextPosition] ?? null;
|
|
3306
|
+
}
|
|
3307
|
+
function resolveVisualBoundary(model, boundary) {
|
|
3308
|
+
return boundary === 'first'
|
|
3309
|
+
? model.selectableKeys[0] ?? null
|
|
3310
|
+
: model.selectableKeys[model.selectableKeys.length - 1] ?? null;
|
|
3311
|
+
}
|
|
3312
|
+
/** Return selectable keys in the inclusive visual interval between two keys. */
|
|
3313
|
+
function resolveVisualRange(model, startKey, endKey) {
|
|
3314
|
+
const startPosition = model.positionByKey.get(startKey);
|
|
3315
|
+
const endPosition = model.positionByKey.get(endKey);
|
|
3316
|
+
if (startPosition === undefined || endPosition === undefined)
|
|
3317
|
+
return [];
|
|
3318
|
+
const low = Math.min(startPosition, endPosition);
|
|
3319
|
+
const high = Math.max(startPosition, endPosition);
|
|
3320
|
+
const selectable = new Set(model.selectableKeys);
|
|
3321
|
+
return model.orderedKeys.slice(low, high + 1).filter((key) => selectable.has(key));
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
/**
|
|
3325
|
+
* Return a presentation-only ordering for option keys.
|
|
3326
|
+
*
|
|
3327
|
+
* The source array and selection set are never mutated. Callers remain
|
|
3328
|
+
* responsible for retaining the returned order as the displayed ordering for
|
|
3329
|
+
* the relevant render/open transaction.
|
|
3330
|
+
*/
|
|
3331
|
+
function projectSelectedOptionKeys(orderedKeys, selectedKeys, placement) {
|
|
3332
|
+
const selected = [];
|
|
3333
|
+
const unselected = [];
|
|
3334
|
+
for (const key of orderedKeys) {
|
|
3335
|
+
(selectedKeys.has(key) ? selected : unselected).push(key);
|
|
3336
|
+
}
|
|
3337
|
+
return [...selected, ...unselected];
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Stably partitions selected keys to the front of each group independently.
|
|
3341
|
+
* Group order, identity, membership, and the source arrays are preserved.
|
|
3342
|
+
*/
|
|
3343
|
+
function projectSelectedOptionGroups(groups, selectedKeys) {
|
|
3344
|
+
return groups.map(({ groupIdentity, orderedKeys }) => {
|
|
3345
|
+
const selected = [];
|
|
3346
|
+
const unselected = [];
|
|
3347
|
+
for (const key of orderedKeys) {
|
|
3348
|
+
(selectedKeys.has(key) ? selected : unselected).push(key);
|
|
3349
|
+
}
|
|
3350
|
+
return { groupIdentity, orderedKeys: [...selected, ...unselected] };
|
|
3351
|
+
});
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
/** Resolve the selected key at an edge of the displayed eligible ordering. */
|
|
3355
|
+
function resolveSelectedTargetKey(orderedKeys, selectedKeys, target) {
|
|
3356
|
+
if (target === 'first') {
|
|
3357
|
+
for (const key of orderedKeys) {
|
|
3358
|
+
if (selectedKeys.has(key))
|
|
3359
|
+
return key;
|
|
3360
|
+
}
|
|
3361
|
+
return null;
|
|
3362
|
+
}
|
|
3363
|
+
for (let index = orderedKeys.length - 1; index >= 0; index -= 1) {
|
|
3364
|
+
const key = orderedKeys[index];
|
|
3365
|
+
if (selectedKeys.has(key))
|
|
3366
|
+
return key;
|
|
3367
|
+
}
|
|
3368
|
+
return null;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3160
3371
|
/**
|
|
3161
3372
|
* DOM-independent coordinator for the opt-in acknowledged data-loading
|
|
3162
3373
|
* protocol. This module is intentionally not re-exported from the package
|
|
@@ -4232,6 +4443,15 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4232
4443
|
super();
|
|
4233
4444
|
this._dataLoadingConfig = { ...LEGACY_DATA_LOADING_CONFIG };
|
|
4234
4445
|
this._hasLastInvalidDataLoadingCandidate = false;
|
|
4446
|
+
this._selectedLabelTooltipTrigger = null;
|
|
4447
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
4448
|
+
this._selectedLabelTooltipFocusTrigger = null;
|
|
4449
|
+
this._selectedLabelTooltipPointerInside = false;
|
|
4450
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
4451
|
+
this._selectedLabelTooltipHideTimer = null;
|
|
4452
|
+
this._selectedLabelTooltipResizeObserver = null;
|
|
4453
|
+
this._selectedLabelTooltipMeasureFrame = null;
|
|
4454
|
+
this._selectedLabelKeys = new WeakMap();
|
|
4235
4455
|
this._busyPresentationVisible = false;
|
|
4236
4456
|
this._busyPresentationStartedAt = null;
|
|
4237
4457
|
this._busyPresentationGeneration = 0;
|
|
@@ -4251,8 +4471,27 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4251
4471
|
filteredIndices: [],
|
|
4252
4472
|
filteredKeys: [],
|
|
4253
4473
|
intendedRenderKeys: [],
|
|
4474
|
+
displayIndexByKey: new Map(),
|
|
4475
|
+
sourceIndexByKey: new Map(),
|
|
4254
4476
|
filteredIndexByKey: new Map(),
|
|
4477
|
+
groupedPresentation: [],
|
|
4478
|
+
};
|
|
4479
|
+
// Presentation policy and membership are snapshotted when the dropdown opens
|
|
4480
|
+
// so selection/config updates cannot reorder an active list.
|
|
4481
|
+
this._selectedOptionsSelectionAtOpen = null;
|
|
4482
|
+
this._selectedOptionsConfigAtOpen = {
|
|
4483
|
+
placement: 'original',
|
|
4484
|
+
groupedPlacement: 'within-group',
|
|
4485
|
+
};
|
|
4486
|
+
this._scrollToSelectedConfigAtOpen = {
|
|
4487
|
+
enabled: true,
|
|
4488
|
+
multiSelectTarget: 'first',
|
|
4489
|
+
onOpen: 'reveal',
|
|
4490
|
+
behavior: 'smooth',
|
|
4491
|
+
block: 'nearest',
|
|
4255
4492
|
};
|
|
4493
|
+
this._closedOptionsViewportAnchor = null;
|
|
4494
|
+
this._openOptionsViewportAnchor = null;
|
|
4256
4495
|
this._emptyStateContext = null;
|
|
4257
4496
|
// Null keeps the public/default renderer on its legacy full path. This
|
|
4258
4497
|
// private state is only used by guarded virtualization integration.
|
|
@@ -4309,9 +4548,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4309
4548
|
this._boundArrowClick = null;
|
|
4310
4549
|
this._pendingFirstRenderMark = false;
|
|
4311
4550
|
this._pendingSearchRenderMark = false;
|
|
4312
|
-
this.
|
|
4551
|
+
this._rangeAnchorKey = null;
|
|
4313
4552
|
/** Chip identity is tracked independently of dropdown option positions. */
|
|
4314
4553
|
this._lastRenderedChipKeys = null;
|
|
4554
|
+
/** Stable presentation nodes keyed by the engine's selected-item identity. */
|
|
4555
|
+
this._chipElements = new Map();
|
|
4556
|
+
this._chipExitStates = new Map();
|
|
4315
4557
|
this._latestChipScrollGeneration = 0;
|
|
4316
4558
|
this._latestChipScrollFrame = null;
|
|
4317
4559
|
this._customOptionBoundElements = new WeakSet();
|
|
@@ -4327,6 +4569,9 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4327
4569
|
this._lifecycleTimers = new Set();
|
|
4328
4570
|
this._lifecycleRafs = new Set();
|
|
4329
4571
|
this._keyboardActiveChangeGeneration = 0;
|
|
4572
|
+
/** Invalidates selected-option positioning scheduled by an earlier opening. */
|
|
4573
|
+
this._openSelectedScrollGeneration = 0;
|
|
4574
|
+
this._openSelectedScrollCleanup = null;
|
|
4330
4575
|
this._tracking = { events: [], styles: [], limitations: [] };
|
|
4331
4576
|
this._suppressBlurClose = false;
|
|
4332
4577
|
this._renderCycleId = 0;
|
|
@@ -4394,6 +4639,14 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4394
4639
|
this._handleClose('outside-pointer');
|
|
4395
4640
|
}
|
|
4396
4641
|
};
|
|
4642
|
+
this._scheduleSelectedLabelTooltipMeasure = () => {
|
|
4643
|
+
if (this._selectedLabelTooltipMeasureFrame !== null || !this.isConnected)
|
|
4644
|
+
return;
|
|
4645
|
+
this._selectedLabelTooltipMeasureFrame = this._requestLifecycleFrame(() => {
|
|
4646
|
+
this._selectedLabelTooltipMeasureFrame = null;
|
|
4647
|
+
this._refreshSelectedLabelTooltipMeasurements();
|
|
4648
|
+
});
|
|
4649
|
+
};
|
|
4397
4650
|
this._shadow = this.attachShadow({ mode: 'open' });
|
|
4398
4651
|
this._uniqueId = `enhanced-select-${Math.random().toString(36).substr(2, 9)}`;
|
|
4399
4652
|
this._rendererHelpers = this._buildRendererHelpers();
|
|
@@ -4428,6 +4681,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4428
4681
|
this._inputContainer = this._createInputContainer();
|
|
4429
4682
|
this._inputContent = this._createInputContent();
|
|
4430
4683
|
this._input = this._createInput();
|
|
4684
|
+
this._selectedLabelTooltip = this._createSelectedLabelTooltip();
|
|
4431
4685
|
this._arrowContainer = this._createArrowContainer();
|
|
4432
4686
|
this._clearControl = this._createClearControl();
|
|
4433
4687
|
this._dropdown = this._createDropdown();
|
|
@@ -4453,9 +4707,19 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4453
4707
|
this._runEngineEffects(this._engine.dispatch({ type: 'DISABLED_CHANGED', disabled: !this._config.enabled }));
|
|
4454
4708
|
this._connectionController?.abort();
|
|
4455
4709
|
this._connectionController = new AbortController();
|
|
4710
|
+
this._observeSelectedLabelTooltipTargets();
|
|
4456
4711
|
document.addEventListener('pointerdown', this._onDocumentPointerDown, {
|
|
4457
4712
|
signal: this._connectionController.signal,
|
|
4458
4713
|
});
|
|
4714
|
+
window.addEventListener('resize', this._scheduleSelectedLabelTooltipMeasure, {
|
|
4715
|
+
signal: this._connectionController.signal,
|
|
4716
|
+
passive: true,
|
|
4717
|
+
});
|
|
4718
|
+
window.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, {
|
|
4719
|
+
signal: this._connectionController.signal,
|
|
4720
|
+
passive: true,
|
|
4721
|
+
capture: true,
|
|
4722
|
+
});
|
|
4459
4723
|
// WORKAROUND: Force display style on host element for Angular compatibility
|
|
4460
4724
|
// Angular's rendering seems to not apply :host styles correctly in some cases
|
|
4461
4725
|
// Must be done in connectedCallback when element is attached to DOM
|
|
@@ -4504,7 +4768,9 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4504
4768
|
this._syncListboxAccessibility();
|
|
4505
4769
|
}
|
|
4506
4770
|
disconnectedCallback() {
|
|
4771
|
+
this._cancelOpenSelectedScroll();
|
|
4507
4772
|
this._cancelLatestChipScroll();
|
|
4773
|
+
this._clearChipPresentation();
|
|
4508
4774
|
this._cancelBusyPresentation();
|
|
4509
4775
|
if (this._dataRequestCoordinator) {
|
|
4510
4776
|
const actions = this._dataRequestCoordinator.disconnect();
|
|
@@ -4527,6 +4793,13 @@ class EnhancedSelect extends HTMLElement {
|
|
|
4527
4793
|
this._runEngineEffects(this._engine.dispatch({ type: 'DISCONNECT' }));
|
|
4528
4794
|
this._connectionController?.abort();
|
|
4529
4795
|
this._connectionController = undefined;
|
|
4796
|
+
this._hideSelectedLabelTooltip(true);
|
|
4797
|
+
this._selectedLabelTooltipResizeObserver?.disconnect();
|
|
4798
|
+
this._selectedLabelTooltipResizeObserver = null;
|
|
4799
|
+
if (this._selectedLabelTooltipMeasureFrame !== null) {
|
|
4800
|
+
cancelAnimationFrame(this._selectedLabelTooltipMeasureFrame);
|
|
4801
|
+
this._selectedLabelTooltipMeasureFrame = null;
|
|
4802
|
+
}
|
|
4530
4803
|
this._asyncGeneration += 1;
|
|
4531
4804
|
this._cancelGuardedVirtualWindowUpdate();
|
|
4532
4805
|
this._clearLifecycleTasks();
|
|
@@ -5090,12 +5363,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5090
5363
|
duplicateKeyPolicy: this._getDuplicateKeyPolicy(),
|
|
5091
5364
|
});
|
|
5092
5365
|
const activeKey = this._engine.state.activeKey;
|
|
5093
|
-
const anchorKey = this.
|
|
5366
|
+
const anchorKey = this._rangeAnchorKey;
|
|
5094
5367
|
this._itemRegistry = registry;
|
|
5095
5368
|
this._state.loadedItems = items;
|
|
5096
5369
|
this._registryItemsRef = items;
|
|
5097
5370
|
const disabledKeys = this._getBlockedDisabledKeys();
|
|
5098
|
-
this.
|
|
5371
|
+
this._rangeAnchorKey = anchorKey !== null && registry.keyToRecord.has(anchorKey) ? anchorKey : null;
|
|
5099
5372
|
this._engine.dispatch({
|
|
5100
5373
|
type: 'ITEMS_REGISTERED',
|
|
5101
5374
|
keys: registry.records.map((record) => record.key),
|
|
@@ -5678,6 +5951,14 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5678
5951
|
input.setAttribute('aria-haspopup', 'listbox');
|
|
5679
5952
|
return input;
|
|
5680
5953
|
}
|
|
5954
|
+
_createSelectedLabelTooltip() {
|
|
5955
|
+
const tooltip = document.createElement('div');
|
|
5956
|
+
tooltip.id = `${this._uniqueId}-selected-label-tooltip`;
|
|
5957
|
+
tooltip.className = 'selected-label-tooltip';
|
|
5958
|
+
tooltip.setAttribute('role', 'tooltip');
|
|
5959
|
+
tooltip.hidden = true;
|
|
5960
|
+
return tooltip;
|
|
5961
|
+
}
|
|
5681
5962
|
_createDropdown() {
|
|
5682
5963
|
const dropdown = document.createElement('div');
|
|
5683
5964
|
dropdown.className = 'select-dropdown';
|
|
@@ -5772,6 +6053,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5772
6053
|
if (this._errorDescription) {
|
|
5773
6054
|
this._shadow.appendChild(this._errorDescription);
|
|
5774
6055
|
}
|
|
6056
|
+
this._shadow.appendChild(this._selectedLabelTooltip);
|
|
5775
6057
|
// Set ARIA relationships
|
|
5776
6058
|
const listboxId = `${this._uniqueId}-listbox`;
|
|
5777
6059
|
this._dropdown.id = listboxId;
|
|
@@ -5786,6 +6068,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5786
6068
|
ELEGANT SELECT COMPONENT — Refined Design System
|
|
5787
6069
|
Formal aesthetics with sophisticated microinteractions
|
|
5788
6070
|
═══════════════════════════════════════════════════════════════════════════ */
|
|
6071
|
+
|
|
6072
|
+
@layer smilodon-input-content-fallback {
|
|
6073
|
+
.input-container.input-container--multi:not([data-multi-scroll-mode="horizontal"]) .input-content {
|
|
6074
|
+
padding-inline-end: var(--select-multi-input-end-gap, 12px);
|
|
6075
|
+
}
|
|
6076
|
+
}
|
|
5789
6077
|
|
|
5790
6078
|
:host {
|
|
5791
6079
|
--select-primary: #1a1a2e;
|
|
@@ -5810,6 +6098,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
5810
6098
|
--select-transition-smooth: 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
5811
6099
|
--select-transition-bounce: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
5812
6100
|
--select-badge-animation: badgeEnter 300ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
|
|
6101
|
+
--select-badge-exit-from-opacity: 1;
|
|
6102
|
+
--select-badge-exit-from-transform: scale(1) translateY(0);
|
|
6103
|
+
--select-badge-exit-to-opacity: 0;
|
|
6104
|
+
--select-badge-exit-to-transform: scale(0.8) translateY(-4px);
|
|
5813
6105
|
--select-badge-enter-from-opacity: 0;
|
|
5814
6106
|
--select-badge-enter-from-transform: scale(0.8) translateY(-4px);
|
|
5815
6107
|
--select-badge-enter-to-opacity: 1;
|
|
@@ -6011,7 +6303,13 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6011
6303
|
transform var(--select-transition-bounce),
|
|
6012
6304
|
box-shadow var(--select-transition-fast),
|
|
6013
6305
|
background var(--select-transition-fast);
|
|
6014
|
-
animation: var(--select-badge-animation);
|
|
6306
|
+
animation: var(--select-badge-enter-animation, var(--select-badge-animation));
|
|
6307
|
+
}
|
|
6308
|
+
|
|
6309
|
+
.selection-badge[data-motion="exiting"] {
|
|
6310
|
+
animation: var(--select-badge-exit-animation, none);
|
|
6311
|
+
pointer-events: none;
|
|
6312
|
+
transition: none;
|
|
6015
6313
|
}
|
|
6016
6314
|
|
|
6017
6315
|
@keyframes badgeEnter {
|
|
@@ -6024,6 +6322,17 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6024
6322
|
transform: var(--select-badge-enter-to-transform);
|
|
6025
6323
|
}
|
|
6026
6324
|
}
|
|
6325
|
+
|
|
6326
|
+
@keyframes badgeExit {
|
|
6327
|
+
0% {
|
|
6328
|
+
opacity: var(--select-badge-exit-from-opacity, 1);
|
|
6329
|
+
transform: var(--select-badge-exit-from-transform, scale(1) translateY(0));
|
|
6330
|
+
}
|
|
6331
|
+
100% {
|
|
6332
|
+
opacity: var(--select-badge-exit-to-opacity, 0);
|
|
6333
|
+
transform: var(--select-badge-exit-to-transform, scale(0.8) translateY(-4px));
|
|
6334
|
+
}
|
|
6335
|
+
}
|
|
6027
6336
|
|
|
6028
6337
|
.selection-badge:hover {
|
|
6029
6338
|
background: var(--select-badge-hover-bg, var(--select-badge-bg, linear-gradient(135deg, var(--select-accent) 0%, var(--select-primary-light) 100%)));
|
|
@@ -6136,6 +6445,29 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6136
6445
|
position: relative;
|
|
6137
6446
|
width: 100%;
|
|
6138
6447
|
}
|
|
6448
|
+
|
|
6449
|
+
.selected-label-tooltip {
|
|
6450
|
+
position: fixed;
|
|
6451
|
+
z-index: 2147483000;
|
|
6452
|
+
box-sizing: border-box;
|
|
6453
|
+
width: max-content;
|
|
6454
|
+
max-width: min(24rem, calc(100vw - 16px));
|
|
6455
|
+
padding: 8px 10px;
|
|
6456
|
+
border: 1px solid rgba(255, 255, 255, 0.18);
|
|
6457
|
+
border-radius: 6px;
|
|
6458
|
+
background: #18202e;
|
|
6459
|
+
color: #fff;
|
|
6460
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
|
|
6461
|
+
font: 500 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
6462
|
+
white-space: normal;
|
|
6463
|
+
overflow-wrap: anywhere;
|
|
6464
|
+
pointer-events: auto;
|
|
6465
|
+
direction: inherit;
|
|
6466
|
+
}
|
|
6467
|
+
|
|
6468
|
+
.selected-label-tooltip[hidden] {
|
|
6469
|
+
display: none;
|
|
6470
|
+
}
|
|
6139
6471
|
|
|
6140
6472
|
.input-container {
|
|
6141
6473
|
position: relative;
|
|
@@ -6184,6 +6516,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6184
6516
|
overflow-y: var(--select-input-overflow-y, hidden);
|
|
6185
6517
|
scrollbar-width: thin;
|
|
6186
6518
|
box-sizing: border-box;
|
|
6519
|
+
padding: var(--select-input-content-padding, revert-layer);
|
|
6187
6520
|
}
|
|
6188
6521
|
|
|
6189
6522
|
.input-container:hover {
|
|
@@ -6209,7 +6542,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6209
6542
|
align-content: var(--select-multi-input-align-content, var(--select-multi-input-align-content-config, flex-start));
|
|
6210
6543
|
overflow-x: var(--select-multi-input-overflow-x, var(--select-multi-input-overflow-x-config, hidden));
|
|
6211
6544
|
overflow-y: var(--select-multi-input-overflow-y, var(--select-multi-input-overflow-y-config, auto));
|
|
6212
|
-
padding-inline-end: var(--select-multi-input-end-gap, 12px);
|
|
6213
6545
|
}
|
|
6214
6546
|
|
|
6215
6547
|
.input-container.input-container--multi .input-content .selection-badge {
|
|
@@ -6247,7 +6579,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6247
6579
|
overflow-y: hidden;
|
|
6248
6580
|
overscroll-behavior-x: contain;
|
|
6249
6581
|
overscroll-behavior-y: none;
|
|
6250
|
-
padding-
|
|
6582
|
+
padding: var(--select-input-content-padding, 0);
|
|
6251
6583
|
scroll-padding-inline-end: var(--select-multi-action-area-width, var(--select-arrow-width, 42px));
|
|
6252
6584
|
}
|
|
6253
6585
|
|
|
@@ -6350,6 +6682,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
6350
6682
|
bottom: 0;
|
|
6351
6683
|
width: var(--select-arrow-width, var(--select-arrow-size, 42px));
|
|
6352
6684
|
height: var(--select-arrow-height, var(--select-arrow-size, auto));
|
|
6685
|
+
padding: var(--select-dropdown-arrow-container-padding, 0);
|
|
6353
6686
|
display: flex;
|
|
6354
6687
|
align-items: center;
|
|
6355
6688
|
justify-content: center;
|
|
@@ -7229,7 +7562,25 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7229
7562
|
this._shadow.appendChild(style);
|
|
7230
7563
|
}
|
|
7231
7564
|
}
|
|
7565
|
+
_isArrowOrClearControlEvent(event) {
|
|
7566
|
+
const path = event.composedPath();
|
|
7567
|
+
return ((this._arrowContainer != null && path.includes(this._arrowContainer)) ||
|
|
7568
|
+
(this._clearControl != null && path.includes(this._clearControl)));
|
|
7569
|
+
}
|
|
7232
7570
|
_attachEventListeners() {
|
|
7571
|
+
this._shadow.addEventListener('pointerover', (event) => this._handleSelectedLabelPointerOver(event));
|
|
7572
|
+
this._shadow.addEventListener('pointerout', (event) => this._handleSelectedLabelPointerOut(event));
|
|
7573
|
+
this._shadow.addEventListener('focusin', (event) => this._handleSelectedLabelFocusIn(event));
|
|
7574
|
+
this._shadow.addEventListener('focusout', (event) => this._handleSelectedLabelFocusOut(event));
|
|
7575
|
+
this._shadow.addEventListener('keydown', (event) => {
|
|
7576
|
+
const keyboardEvent = event;
|
|
7577
|
+
if (keyboardEvent.key !== 'Escape' || this._selectedLabelTooltip.hidden)
|
|
7578
|
+
return;
|
|
7579
|
+
keyboardEvent.preventDefault();
|
|
7580
|
+
keyboardEvent.stopPropagation();
|
|
7581
|
+
this._dismissSelectedLabelTooltip();
|
|
7582
|
+
});
|
|
7583
|
+
this._inputContent.addEventListener('scroll', this._scheduleSelectedLabelTooltipMeasure, { passive: true });
|
|
7233
7584
|
// Arrow click handler
|
|
7234
7585
|
if (this._arrowContainer) {
|
|
7235
7586
|
this._boundArrowClick = (e) => {
|
|
@@ -7265,13 +7616,11 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7265
7616
|
// Prevent propagation to document click listener but do NOT preventDefault.
|
|
7266
7617
|
// Allow default so browser events (click) on newly opened options still fire.
|
|
7267
7618
|
// e.stopPropagation(); // BUG: By stopping propagation here, the document click listener doesn't see it, which is fine for not closing it. But be very careful.
|
|
7268
|
-
const target = e.target;
|
|
7269
7619
|
if (!this._config.enabled)
|
|
7270
7620
|
return;
|
|
7271
|
-
if (
|
|
7272
|
-
return;
|
|
7273
|
-
if (target && target.closest('.clear-control-button'))
|
|
7621
|
+
if (this._isArrowOrClearControlEvent(e))
|
|
7274
7622
|
return;
|
|
7623
|
+
const target = e.target;
|
|
7275
7624
|
if (this._isPointerOnInputScrollbar(e)) {
|
|
7276
7625
|
this._suppressNextOpenClick = true;
|
|
7277
7626
|
return;
|
|
@@ -7318,7 +7667,6 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7318
7667
|
}
|
|
7319
7668
|
});
|
|
7320
7669
|
this._inputContainer.addEventListener('click', (e) => {
|
|
7321
|
-
const target = e.target;
|
|
7322
7670
|
const isHorizontalMultiMode = this._config.selection.mode === 'multi'
|
|
7323
7671
|
&& (this._config.multiSelectDisplay?.mode ?? 'wrap') === 'horizontal';
|
|
7324
7672
|
if (!this._config.enabled || !isHorizontalMultiMode) {
|
|
@@ -7326,7 +7674,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7326
7674
|
this._multiScrollDrag.moved = false;
|
|
7327
7675
|
return;
|
|
7328
7676
|
}
|
|
7329
|
-
if (
|
|
7677
|
+
if (this._isArrowOrClearControlEvent(e)) {
|
|
7330
7678
|
this._suppressNextOpenClick = false;
|
|
7331
7679
|
this._multiScrollDrag.moved = false;
|
|
7332
7680
|
return;
|
|
@@ -7401,6 +7749,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7401
7749
|
if (!this._config.searchable)
|
|
7402
7750
|
return;
|
|
7403
7751
|
const query = e.target.value;
|
|
7752
|
+
if (this._selectedLabelTooltipTrigger === this._input
|
|
7753
|
+
&& this._getSelectedLabelForTrigger(this._input) === null) {
|
|
7754
|
+
this._hideSelectedLabelTooltip();
|
|
7755
|
+
}
|
|
7404
7756
|
this._handleSearch(query);
|
|
7405
7757
|
});
|
|
7406
7758
|
// If the user presses down inside the options container we should
|
|
@@ -7563,6 +7915,286 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7563
7915
|
return index === undefined ? null : this._getOptionElementByIndex(index);
|
|
7564
7916
|
},
|
|
7565
7917
|
});
|
|
7918
|
+
this._syncSelectedLabelTooltipDescription();
|
|
7919
|
+
}
|
|
7920
|
+
_selectedLabelTriggerFromTarget(target) {
|
|
7921
|
+
if (!(target instanceof HTMLElement))
|
|
7922
|
+
return null;
|
|
7923
|
+
if (target === this._input)
|
|
7924
|
+
return target;
|
|
7925
|
+
const label = target.closest('.selection-badge-label');
|
|
7926
|
+
return label && this._inputContent.contains(label) ? label : null;
|
|
7927
|
+
}
|
|
7928
|
+
_getSelectedLabelForTrigger(trigger) {
|
|
7929
|
+
const entries = this._getSelectedEntries();
|
|
7930
|
+
if (trigger === this._input) {
|
|
7931
|
+
if (this._config.selection.mode !== 'single' || this._state.searchQuery.length > 0)
|
|
7932
|
+
return null;
|
|
7933
|
+
const item = entries[0]?.item;
|
|
7934
|
+
if (item === undefined)
|
|
7935
|
+
return null;
|
|
7936
|
+
const label = this._getItemLabel(item);
|
|
7937
|
+
return this._input.value === label ? label : null;
|
|
7938
|
+
}
|
|
7939
|
+
if (!trigger.classList.contains('selection-badge-label'))
|
|
7940
|
+
return null;
|
|
7941
|
+
const key = this._selectedLabelKeys.get(trigger);
|
|
7942
|
+
if (key === undefined)
|
|
7943
|
+
return null;
|
|
7944
|
+
const entry = entries.find((candidate) => candidate.key === key);
|
|
7945
|
+
if (!entry)
|
|
7946
|
+
return null;
|
|
7947
|
+
const label = this._getItemLabel(entry.item);
|
|
7948
|
+
return trigger.textContent === label ? label : null;
|
|
7949
|
+
}
|
|
7950
|
+
_isSelectedLabelTruncated(trigger) {
|
|
7951
|
+
if (!trigger.isConnected)
|
|
7952
|
+
return false;
|
|
7953
|
+
return trigger.clientWidth > 0 && trigger.scrollWidth > trigger.clientWidth + 1;
|
|
7954
|
+
}
|
|
7955
|
+
_handleSelectedLabelPointerOver(event) {
|
|
7956
|
+
const target = event.target;
|
|
7957
|
+
if (target?.closest('.selected-label-tooltip') === this._selectedLabelTooltip) {
|
|
7958
|
+
this._selectedLabelTooltipPointerInside = true;
|
|
7959
|
+
this._clearSelectedLabelTooltipHideTimer();
|
|
7960
|
+
return;
|
|
7961
|
+
}
|
|
7962
|
+
const trigger = this._selectedLabelTriggerFromTarget(target);
|
|
7963
|
+
if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
|
|
7964
|
+
return;
|
|
7965
|
+
this._selectedLabelTooltipPointerTrigger = trigger;
|
|
7966
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
7967
|
+
this._showSelectedLabelTooltip(trigger);
|
|
7968
|
+
}
|
|
7969
|
+
_handleSelectedLabelPointerOut(event) {
|
|
7970
|
+
const target = event.target;
|
|
7971
|
+
if (target === this._selectedLabelTooltip || this._selectedLabelTooltip.contains(target)) {
|
|
7972
|
+
if (event.relatedTarget instanceof Node && this._selectedLabelTooltip.contains(event.relatedTarget))
|
|
7973
|
+
return;
|
|
7974
|
+
this._selectedLabelTooltipPointerInside = false;
|
|
7975
|
+
this._scheduleSelectedLabelTooltipHide();
|
|
7976
|
+
return;
|
|
7977
|
+
}
|
|
7978
|
+
const trigger = this._selectedLabelTriggerFromTarget(target);
|
|
7979
|
+
if (!trigger || (event.relatedTarget instanceof Node && trigger.contains(event.relatedTarget)))
|
|
7980
|
+
return;
|
|
7981
|
+
if (this._selectedLabelTooltipPointerTrigger === trigger) {
|
|
7982
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
7983
|
+
if (this._selectedLabelTooltipDismissedTrigger === trigger) {
|
|
7984
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
7985
|
+
}
|
|
7986
|
+
}
|
|
7987
|
+
if (event.relatedTarget === this._selectedLabelTooltip) {
|
|
7988
|
+
this._selectedLabelTooltipPointerInside = true;
|
|
7989
|
+
this._clearSelectedLabelTooltipHideTimer();
|
|
7990
|
+
return;
|
|
7991
|
+
}
|
|
7992
|
+
this._scheduleSelectedLabelTooltipHide();
|
|
7993
|
+
}
|
|
7994
|
+
_handleSelectedLabelFocusIn(event) {
|
|
7995
|
+
const trigger = this._selectedLabelTriggerFromTarget(event.target);
|
|
7996
|
+
if (!trigger)
|
|
7997
|
+
return;
|
|
7998
|
+
this._selectedLabelTooltipFocusTrigger = trigger;
|
|
7999
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
8000
|
+
this._showSelectedLabelTooltip(trigger);
|
|
8001
|
+
}
|
|
8002
|
+
_handleSelectedLabelFocusOut(event) {
|
|
8003
|
+
const trigger = this._selectedLabelTriggerFromTarget(event.target);
|
|
8004
|
+
if (!trigger || this._selectedLabelTooltipFocusTrigger !== trigger)
|
|
8005
|
+
return;
|
|
8006
|
+
this._selectedLabelTooltipFocusTrigger = null;
|
|
8007
|
+
if (this._selectedLabelTooltipDismissedTrigger === trigger) {
|
|
8008
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
8009
|
+
}
|
|
8010
|
+
this._scheduleSelectedLabelTooltipHide();
|
|
8011
|
+
}
|
|
8012
|
+
_showSelectedLabelTooltip(trigger) {
|
|
8013
|
+
if (this._selectedLabelTooltipDismissedTrigger === trigger)
|
|
8014
|
+
return;
|
|
8015
|
+
if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
|
|
8016
|
+
if (this._selectedLabelTooltipTrigger === trigger)
|
|
8017
|
+
this._hideSelectedLabelTooltip();
|
|
8018
|
+
return;
|
|
8019
|
+
}
|
|
8020
|
+
const label = this._getSelectedLabelForTrigger(trigger);
|
|
8021
|
+
if (label === null || !this._isSelectedLabelTruncated(trigger)) {
|
|
8022
|
+
if (trigger.classList.contains('selection-badge-label'))
|
|
8023
|
+
trigger.tabIndex = -1;
|
|
8024
|
+
if (this._selectedLabelTooltipTrigger === trigger)
|
|
8025
|
+
this._hideSelectedLabelTooltip();
|
|
8026
|
+
return;
|
|
8027
|
+
}
|
|
8028
|
+
if (trigger.classList.contains('selection-badge-label'))
|
|
8029
|
+
trigger.tabIndex = 0;
|
|
8030
|
+
if (this._selectedLabelTooltipTrigger !== trigger) {
|
|
8031
|
+
this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
|
|
8032
|
+
this._selectedLabelTooltipTrigger = trigger;
|
|
8033
|
+
}
|
|
8034
|
+
this._selectedLabelTooltip.textContent = label;
|
|
8035
|
+
this._selectedLabelTooltip.hidden = false;
|
|
8036
|
+
this._positionSelectedLabelTooltip(trigger);
|
|
8037
|
+
this._syncSelectedLabelTooltipDescription();
|
|
8038
|
+
this._clearSelectedLabelTooltipHideTimer();
|
|
8039
|
+
}
|
|
8040
|
+
_positionSelectedLabelTooltip(trigger) {
|
|
8041
|
+
if (this._selectedLabelTooltip.hidden || !trigger.isConnected)
|
|
8042
|
+
return;
|
|
8043
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
8044
|
+
const tooltip = this._selectedLabelTooltip;
|
|
8045
|
+
tooltip.style.maxWidth = `min(24rem, calc(100vw - 16px))`;
|
|
8046
|
+
tooltip.style.direction = getComputedStyle(trigger).direction;
|
|
8047
|
+
const tooltipRect = tooltip.getBoundingClientRect();
|
|
8048
|
+
const viewportWidth = document.documentElement.clientWidth || window.innerWidth;
|
|
8049
|
+
const viewportHeight = document.documentElement.clientHeight || window.innerHeight;
|
|
8050
|
+
const rtl = getComputedStyle(trigger).direction === 'rtl';
|
|
8051
|
+
const desiredLeft = rtl ? triggerRect.right - tooltipRect.width : triggerRect.left;
|
|
8052
|
+
const left = Math.max(8, Math.min(desiredLeft, viewportWidth - tooltipRect.width - 8));
|
|
8053
|
+
const above = triggerRect.top - tooltipRect.height - 6;
|
|
8054
|
+
const top = above >= 8 ? above : Math.min(triggerRect.bottom + 6, viewportHeight - tooltipRect.height - 8);
|
|
8055
|
+
tooltip.style.left = `${left}px`;
|
|
8056
|
+
tooltip.style.top = `${Math.max(8, top)}px`;
|
|
8057
|
+
}
|
|
8058
|
+
_syncSelectedLabelTooltipDescription() {
|
|
8059
|
+
const trigger = this._selectedLabelTooltipTrigger;
|
|
8060
|
+
this._removeSelectedLabelTooltipDescription(trigger);
|
|
8061
|
+
if (trigger && !this._selectedLabelTooltip.hidden) {
|
|
8062
|
+
const ids = new Set((trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean));
|
|
8063
|
+
ids.add(this._selectedLabelTooltip.id);
|
|
8064
|
+
trigger.setAttribute('aria-describedby', [...ids].join(' '));
|
|
8065
|
+
}
|
|
8066
|
+
}
|
|
8067
|
+
_removeSelectedLabelTooltipDescription(trigger) {
|
|
8068
|
+
if (!trigger)
|
|
8069
|
+
return;
|
|
8070
|
+
const ids = (trigger.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(Boolean);
|
|
8071
|
+
const remaining = ids.filter((id) => id !== this._selectedLabelTooltip.id);
|
|
8072
|
+
if (remaining.length)
|
|
8073
|
+
trigger.setAttribute('aria-describedby', remaining.join(' '));
|
|
8074
|
+
else
|
|
8075
|
+
trigger.removeAttribute('aria-describedby');
|
|
8076
|
+
}
|
|
8077
|
+
_dismissSelectedLabelTooltip() {
|
|
8078
|
+
this._selectedLabelTooltipDismissedTrigger = this._selectedLabelTooltipFocusTrigger
|
|
8079
|
+
?? this._selectedLabelTooltipTrigger
|
|
8080
|
+
?? this._selectedLabelTooltipPointerTrigger;
|
|
8081
|
+
this._hideSelectedLabelTooltip();
|
|
8082
|
+
}
|
|
8083
|
+
_hideSelectedLabelTooltip(clearInteractionState = false) {
|
|
8084
|
+
this._clearSelectedLabelTooltipHideTimer();
|
|
8085
|
+
this._removeSelectedLabelTooltipDescription(this._selectedLabelTooltipTrigger);
|
|
8086
|
+
this._selectedLabelTooltipTrigger = null;
|
|
8087
|
+
this._selectedLabelTooltip.hidden = true;
|
|
8088
|
+
if (clearInteractionState) {
|
|
8089
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
8090
|
+
this._selectedLabelTooltipFocusTrigger = null;
|
|
8091
|
+
this._selectedLabelTooltipPointerInside = false;
|
|
8092
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
8093
|
+
}
|
|
8094
|
+
}
|
|
8095
|
+
_clearSelectedLabelTooltipHideTimer() {
|
|
8096
|
+
if (this._selectedLabelTooltipHideTimer === null)
|
|
8097
|
+
return;
|
|
8098
|
+
window.clearTimeout(this._selectedLabelTooltipHideTimer);
|
|
8099
|
+
this._lifecycleTimers.delete(this._selectedLabelTooltipHideTimer);
|
|
8100
|
+
this._selectedLabelTooltipHideTimer = null;
|
|
8101
|
+
}
|
|
8102
|
+
_scheduleSelectedLabelTooltipHide() {
|
|
8103
|
+
this._clearSelectedLabelTooltipHideTimer();
|
|
8104
|
+
this._selectedLabelTooltipHideTimer = this._setLifecycleTimeout(() => {
|
|
8105
|
+
this._selectedLabelTooltipHideTimer = null;
|
|
8106
|
+
if (this._selectedLabelTooltipPointerInside)
|
|
8107
|
+
return;
|
|
8108
|
+
const trigger = this._selectedLabelTooltipTrigger;
|
|
8109
|
+
if (trigger && (this._selectedLabelTooltipFocusTrigger === trigger
|
|
8110
|
+
|| this._selectedLabelTooltipPointerTrigger === trigger))
|
|
8111
|
+
return;
|
|
8112
|
+
const focusedTrigger = this._selectedLabelTooltipFocusTrigger;
|
|
8113
|
+
if (focusedTrigger && focusedTrigger !== this._selectedLabelTooltipDismissedTrigger
|
|
8114
|
+
&& focusedTrigger.isConnected
|
|
8115
|
+
&& this._isSelectedLabelVisibleInViewport(focusedTrigger)) {
|
|
8116
|
+
this._showSelectedLabelTooltip(focusedTrigger);
|
|
8117
|
+
return;
|
|
8118
|
+
}
|
|
8119
|
+
this._hideSelectedLabelTooltip();
|
|
8120
|
+
}, 180);
|
|
8121
|
+
}
|
|
8122
|
+
_isSelectedLabelVisibleInViewport(trigger) {
|
|
8123
|
+
if (!trigger.classList.contains('selection-badge-label'))
|
|
8124
|
+
return true;
|
|
8125
|
+
const viewport = this._inputContent;
|
|
8126
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
8127
|
+
const viewportRect = viewport.getBoundingClientRect();
|
|
8128
|
+
// DOM-only test environments do not calculate layout rectangles. Leave
|
|
8129
|
+
// visibility indeterminate there; browser measurement handles real layout.
|
|
8130
|
+
if (triggerRect.width === 0 && triggerRect.height === 0
|
|
8131
|
+
&& viewportRect.width === 0 && viewportRect.height === 0)
|
|
8132
|
+
return true;
|
|
8133
|
+
const left = viewportRect.left + viewport.clientLeft;
|
|
8134
|
+
const top = viewportRect.top + viewport.clientTop;
|
|
8135
|
+
const right = left + viewport.clientWidth;
|
|
8136
|
+
const bottom = top + viewport.clientHeight;
|
|
8137
|
+
return triggerRect.right > left && triggerRect.left < right
|
|
8138
|
+
&& triggerRect.bottom > top && triggerRect.top < bottom;
|
|
8139
|
+
}
|
|
8140
|
+
_observeSelectedLabelTooltipTargets() {
|
|
8141
|
+
if (typeof ResizeObserver === 'undefined')
|
|
8142
|
+
return;
|
|
8143
|
+
const hasSingleSelection = this._config.selection.mode === 'single'
|
|
8144
|
+
&& this._getSelectedEntries().length > 0;
|
|
8145
|
+
const chipLabels = this._getActiveChipBadges()
|
|
8146
|
+
.map((badge) => badge.querySelector('.selection-badge-label'))
|
|
8147
|
+
.filter((label) => label !== null);
|
|
8148
|
+
if (!hasSingleSelection && chipLabels.length === 0) {
|
|
8149
|
+
this._selectedLabelTooltipResizeObserver?.disconnect();
|
|
8150
|
+
this._selectedLabelTooltipResizeObserver = null;
|
|
8151
|
+
return;
|
|
8152
|
+
}
|
|
8153
|
+
if (!this._selectedLabelTooltipResizeObserver) {
|
|
8154
|
+
this._selectedLabelTooltipResizeObserver = new ResizeObserver(() => this._scheduleSelectedLabelTooltipMeasure());
|
|
8155
|
+
}
|
|
8156
|
+
this._selectedLabelTooltipResizeObserver.disconnect();
|
|
8157
|
+
if (hasSingleSelection)
|
|
8158
|
+
this._selectedLabelTooltipResizeObserver.observe(this._input);
|
|
8159
|
+
chipLabels.forEach((label) => {
|
|
8160
|
+
this._selectedLabelTooltipResizeObserver?.observe(label);
|
|
8161
|
+
});
|
|
8162
|
+
}
|
|
8163
|
+
_refreshSelectedLabelTooltipMeasurements() {
|
|
8164
|
+
this._getActiveChipBadges().forEach((badge) => {
|
|
8165
|
+
const label = badge.querySelector('.selection-badge-label');
|
|
8166
|
+
if (!label)
|
|
8167
|
+
return;
|
|
8168
|
+
label.tabIndex = this._isSelectedLabelTruncated(label) ? 0 : -1;
|
|
8169
|
+
});
|
|
8170
|
+
const currentTrigger = this._selectedLabelTooltipTrigger;
|
|
8171
|
+
if (currentTrigger?.classList.contains('selection-badge-label')
|
|
8172
|
+
&& !this._isSelectedLabelVisibleInViewport(currentTrigger)) {
|
|
8173
|
+
if (this._selectedLabelTooltipPointerTrigger === currentTrigger) {
|
|
8174
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
8175
|
+
}
|
|
8176
|
+
this._hideSelectedLabelTooltip();
|
|
8177
|
+
}
|
|
8178
|
+
const trigger = this._selectedLabelTooltipTrigger
|
|
8179
|
+
?? this._selectedLabelTooltipFocusTrigger
|
|
8180
|
+
?? this._selectedLabelTooltipPointerTrigger;
|
|
8181
|
+
if (!trigger)
|
|
8182
|
+
return;
|
|
8183
|
+
if (!trigger.isConnected || !this._isSelectedLabelVisibleInViewport(trigger)) {
|
|
8184
|
+
if (this._selectedLabelTooltipPointerTrigger === trigger) {
|
|
8185
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
8186
|
+
}
|
|
8187
|
+
if (this._selectedLabelTooltipTrigger === trigger)
|
|
8188
|
+
this._hideSelectedLabelTooltip();
|
|
8189
|
+
return;
|
|
8190
|
+
}
|
|
8191
|
+
const label = this._getSelectedLabelForTrigger(trigger);
|
|
8192
|
+
if (label === null || !this._isSelectedLabelTruncated(trigger)) {
|
|
8193
|
+
if (this._selectedLabelTooltipTrigger === trigger)
|
|
8194
|
+
this._hideSelectedLabelTooltip();
|
|
8195
|
+
return;
|
|
8196
|
+
}
|
|
8197
|
+
this._showSelectedLabelTooltip(trigger);
|
|
7566
8198
|
}
|
|
7567
8199
|
_syncListboxAccessibility() {
|
|
7568
8200
|
if (!this._dropdown || !this._engine || !this._state)
|
|
@@ -7640,6 +8272,15 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7640
8272
|
this._dropdown.removeAttribute('inert');
|
|
7641
8273
|
this._dropdown.removeAttribute('aria-hidden');
|
|
7642
8274
|
this._markOpenStart();
|
|
8275
|
+
this._scrollToSelectedConfigAtOpen = { ...this._config.scrollToSelected };
|
|
8276
|
+
this._openOptionsViewportAnchor = this._scrollToSelectedConfigAtOpen.onOpen === 'preserve'
|
|
8277
|
+
? (this._closedOptionsViewportAnchor ?? this._captureOptionsViewportAnchor())
|
|
8278
|
+
: null;
|
|
8279
|
+
this._closedOptionsViewportAnchor = null;
|
|
8280
|
+
this._selectedOptionsConfigAtOpen = { ...this._config.selectedOptions };
|
|
8281
|
+
this._selectedOptionsSelectionAtOpen = this._config.selectedOptions.placement === 'selected-first'
|
|
8282
|
+
? new Set(this._engine.state.selectedKeys)
|
|
8283
|
+
: null;
|
|
7643
8284
|
this.setAttribute('data-open', 'true');
|
|
7644
8285
|
this._liftStackingAncestors();
|
|
7645
8286
|
this._dropdown.style.display = 'block';
|
|
@@ -7651,28 +8292,17 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7651
8292
|
this._emit('open', {});
|
|
7652
8293
|
this._config.callbacks.onOpen?.();
|
|
7653
8294
|
this._announce('Options expanded');
|
|
7654
|
-
|
|
7655
|
-
if (this._config.scrollToSelected.enabled) {
|
|
7656
|
-
const keyboardActiveChangeGeneration = this._keyboardActiveChangeGeneration;
|
|
7657
|
-
const canRestoreOpenSelection = () => this._state.isOpen
|
|
7658
|
-
&& this._keyboardActiveChangeGeneration === keyboardActiveChangeGeneration;
|
|
7659
|
-
// Use requestAnimationFrame for better timing after render
|
|
7660
|
-
this._requestLifecycleFrame(() => {
|
|
7661
|
-
if (!canRestoreOpenSelection())
|
|
7662
|
-
return;
|
|
7663
|
-
// Double RAF to ensure layout is complete
|
|
7664
|
-
this._requestLifecycleFrame(() => {
|
|
7665
|
-
if (!canRestoreOpenSelection())
|
|
7666
|
-
return;
|
|
7667
|
-
this._scrollToSelected();
|
|
7668
|
-
});
|
|
7669
|
-
});
|
|
7670
|
-
}
|
|
8295
|
+
this._scheduleOpenSelectedScroll();
|
|
7671
8296
|
}
|
|
7672
8297
|
_handleClose(reason = 'programmatic') {
|
|
8298
|
+
if (this._state.isOpen) {
|
|
8299
|
+
this._closedOptionsViewportAnchor = this._captureOptionsViewportAnchor();
|
|
8300
|
+
}
|
|
7673
8301
|
const effects = this._engine.dispatch({ type: 'CLOSE_REQUEST', reason });
|
|
7674
8302
|
if (!effects.some((effect) => effect.type === 'POPUP_CLOSED'))
|
|
7675
8303
|
return;
|
|
8304
|
+
this._cancelOpenSelectedScroll();
|
|
8305
|
+
this._selectedOptionsSelectionAtOpen = null;
|
|
7676
8306
|
this.removeAttribute('data-open');
|
|
7677
8307
|
this._restoreLiftedAncestors();
|
|
7678
8308
|
this._dropdown.setAttribute('data-placement', this._resolvedDropdownPlacement);
|
|
@@ -7684,6 +8314,257 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7684
8314
|
this._config.callbacks.onClose?.();
|
|
7685
8315
|
this._announce('Options collapsed');
|
|
7686
8316
|
}
|
|
8317
|
+
/**
|
|
8318
|
+
* Defer the one automatic selected-option positioning operation until the
|
|
8319
|
+
* dropdown's own entrance geometry has settled. Logical active/ARIA state
|
|
8320
|
+
* remains synchronous in _setInitialActiveOption().
|
|
8321
|
+
*/
|
|
8322
|
+
_scheduleOpenSelectedScroll() {
|
|
8323
|
+
this._cancelOpenSelectedScroll();
|
|
8324
|
+
const openingConfig = this._scrollToSelectedConfigAtOpen;
|
|
8325
|
+
if (!openingConfig.enabled)
|
|
8326
|
+
return;
|
|
8327
|
+
const generation = this._openSelectedScrollGeneration;
|
|
8328
|
+
const keyboardGeneration = this._keyboardActiveChangeGeneration;
|
|
8329
|
+
const initialScrollTop = this._optionsContainer.scrollTop;
|
|
8330
|
+
const animations = [];
|
|
8331
|
+
const frameIds = new Set();
|
|
8332
|
+
let timerId = null;
|
|
8333
|
+
let completed = false;
|
|
8334
|
+
const isCurrent = () => generation === this._openSelectedScrollGeneration
|
|
8335
|
+
&& this._state.isOpen
|
|
8336
|
+
&& this.isConnected
|
|
8337
|
+
&& this._config.scrollToSelected.enabled
|
|
8338
|
+
&& keyboardGeneration === this._keyboardActiveChangeGeneration;
|
|
8339
|
+
const removeListeners = () => {
|
|
8340
|
+
this._optionsContainer.removeEventListener('wheel', cancelForUserInput);
|
|
8341
|
+
this._optionsContainer.removeEventListener('touchstart', cancelForUserInput);
|
|
8342
|
+
this._optionsContainer.removeEventListener('pointerdown', cancelForUserInput);
|
|
8343
|
+
this._optionsContainer.removeEventListener('scroll', cancelForUserScroll);
|
|
8344
|
+
for (const animation of animations) {
|
|
8345
|
+
animation.removeEventListener('finish', onAnimationStateChange);
|
|
8346
|
+
animation.removeEventListener('cancel', onAnimationStateChange);
|
|
8347
|
+
}
|
|
8348
|
+
};
|
|
8349
|
+
const cleanup = () => {
|
|
8350
|
+
removeListeners();
|
|
8351
|
+
for (const id of frameIds)
|
|
8352
|
+
cancelAnimationFrame(id);
|
|
8353
|
+
frameIds.clear();
|
|
8354
|
+
if (timerId !== null) {
|
|
8355
|
+
clearTimeout(timerId);
|
|
8356
|
+
this._lifecycleTimers.delete(timerId);
|
|
8357
|
+
timerId = null;
|
|
8358
|
+
}
|
|
8359
|
+
if (this._openSelectedScrollCleanup === cleanup) {
|
|
8360
|
+
this._openSelectedScrollCleanup = null;
|
|
8361
|
+
}
|
|
8362
|
+
};
|
|
8363
|
+
const cancelForUserInput = () => this._cancelOpenSelectedScroll();
|
|
8364
|
+
const cancelForUserScroll = () => {
|
|
8365
|
+
if (Math.abs(this._optionsContainer.scrollTop - initialScrollTop) > 1) {
|
|
8366
|
+
this._cancelOpenSelectedScroll();
|
|
8367
|
+
}
|
|
8368
|
+
};
|
|
8369
|
+
const finish = () => {
|
|
8370
|
+
if (completed)
|
|
8371
|
+
return;
|
|
8372
|
+
completed = true;
|
|
8373
|
+
cleanup();
|
|
8374
|
+
if (!isCurrent())
|
|
8375
|
+
return;
|
|
8376
|
+
const frameId = requestAnimationFrame(() => {
|
|
8377
|
+
frameIds.delete(frameId);
|
|
8378
|
+
cleanup();
|
|
8379
|
+
if (!isCurrent())
|
|
8380
|
+
return;
|
|
8381
|
+
if (openingConfig.onOpen === 'preserve') {
|
|
8382
|
+
this._restorePreservedOptionsViewport();
|
|
8383
|
+
}
|
|
8384
|
+
else {
|
|
8385
|
+
this._scrollToSelected({
|
|
8386
|
+
onlyIfNeeded: openingConfig.onOpen === 'reveal',
|
|
8387
|
+
setActive: false,
|
|
8388
|
+
config: openingConfig,
|
|
8389
|
+
});
|
|
8390
|
+
}
|
|
8391
|
+
});
|
|
8392
|
+
frameIds.add(frameId);
|
|
8393
|
+
this._openSelectedScrollCleanup = cleanup;
|
|
8394
|
+
};
|
|
8395
|
+
const onAnimationStateChange = () => {
|
|
8396
|
+
if (animations.every((animation) => animation.playState === 'finished' || animation.playState === 'idle'))
|
|
8397
|
+
finish();
|
|
8398
|
+
};
|
|
8399
|
+
const begin = () => {
|
|
8400
|
+
if (!isCurrent()) {
|
|
8401
|
+
cleanup();
|
|
8402
|
+
return;
|
|
8403
|
+
}
|
|
8404
|
+
const getAnimations = this._dropdown.getAnimations;
|
|
8405
|
+
const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
8406
|
+
if (!reducedMotion && typeof getAnimations === 'function') {
|
|
8407
|
+
for (const animation of getAnimations.call(this._dropdown)) {
|
|
8408
|
+
const timing = animation.effect?.getComputedTiming();
|
|
8409
|
+
if (!timing || timing.iterations === Infinity || animation.playState === 'finished'
|
|
8410
|
+
|| animation.playState === 'idle')
|
|
8411
|
+
continue;
|
|
8412
|
+
animations.push(animation);
|
|
8413
|
+
}
|
|
8414
|
+
}
|
|
8415
|
+
if (animations.length === 0) {
|
|
8416
|
+
if (!reducedMotion && typeof getAnimations !== 'function') {
|
|
8417
|
+
const fallbackWait = this._getDropdownEntranceFallbackDurationMs();
|
|
8418
|
+
if (fallbackWait > 0) {
|
|
8419
|
+
timerId = window.setTimeout(finish, fallbackWait + 34);
|
|
8420
|
+
this._lifecycleTimers.add(timerId);
|
|
8421
|
+
return;
|
|
8422
|
+
}
|
|
8423
|
+
}
|
|
8424
|
+
finish();
|
|
8425
|
+
return;
|
|
8426
|
+
}
|
|
8427
|
+
for (const animation of animations) {
|
|
8428
|
+
animation.addEventListener('finish', onAnimationStateChange);
|
|
8429
|
+
animation.addEventListener('cancel', onAnimationStateChange);
|
|
8430
|
+
}
|
|
8431
|
+
const remainingMs = Math.max(...animations.map((animation) => {
|
|
8432
|
+
const timing = animation.effect?.getComputedTiming();
|
|
8433
|
+
const endTime = Number(timing?.endTime);
|
|
8434
|
+
const currentTime = Number(animation.currentTime ?? 0);
|
|
8435
|
+
return Number.isFinite(endTime) ? Math.max(0, endTime - currentTime) : 0;
|
|
8436
|
+
}));
|
|
8437
|
+
const boundedWait = Math.min(10000, remainingMs + 50);
|
|
8438
|
+
timerId = window.setTimeout(finish, boundedWait);
|
|
8439
|
+
this._lifecycleTimers.add(timerId);
|
|
8440
|
+
};
|
|
8441
|
+
this._optionsContainer.addEventListener('wheel', cancelForUserInput, { passive: true });
|
|
8442
|
+
this._optionsContainer.addEventListener('touchstart', cancelForUserInput, { passive: true });
|
|
8443
|
+
this._optionsContainer.addEventListener('pointerdown', cancelForUserInput, { passive: true });
|
|
8444
|
+
this._optionsContainer.addEventListener('scroll', cancelForUserScroll, { passive: true });
|
|
8445
|
+
this._openSelectedScrollCleanup = cleanup;
|
|
8446
|
+
const frameId = requestAnimationFrame(() => {
|
|
8447
|
+
frameIds.delete(frameId);
|
|
8448
|
+
begin();
|
|
8449
|
+
});
|
|
8450
|
+
frameIds.add(frameId);
|
|
8451
|
+
}
|
|
8452
|
+
_cancelOpenSelectedScroll() {
|
|
8453
|
+
this._openSelectedScrollGeneration += 1;
|
|
8454
|
+
this._openSelectedScrollCleanup?.();
|
|
8455
|
+
this._openSelectedScrollCleanup = null;
|
|
8456
|
+
}
|
|
8457
|
+
_captureOptionsViewportAnchor() {
|
|
8458
|
+
const scroller = this._optionsContainer;
|
|
8459
|
+
const scrollTop = scroller.scrollTop;
|
|
8460
|
+
const order = this._renderPlan.filteredKeys.slice();
|
|
8461
|
+
const viewportTop = scroller.getBoundingClientRect().top + scroller.clientTop;
|
|
8462
|
+
const viewportBottom = viewportTop + scroller.clientHeight;
|
|
8463
|
+
const visible = Array.from(scroller.querySelectorAll('[data-sm-selectable], [data-selectable]'))
|
|
8464
|
+
.map((option) => ({ option, rect: option.getBoundingClientRect() }))
|
|
8465
|
+
.filter(({ rect }) => rect.height > 0 && rect.bottom > viewportTop && rect.top < viewportBottom)
|
|
8466
|
+
.sort((left, right) => left.rect.top - right.rect.top)[0];
|
|
8467
|
+
if (visible) {
|
|
8468
|
+
const sourceIndex = Number(visible.option.getAttribute('data-sm-index') ?? visible.option.getAttribute('data-index'));
|
|
8469
|
+
const key = Number.isInteger(sourceIndex) ? this._itemRegistry.indexToKey.get(sourceIndex) ?? null : null;
|
|
8470
|
+
if (key !== null) {
|
|
8471
|
+
return { key, offset: visible.rect.top - viewportTop, scrollTop, order };
|
|
8472
|
+
}
|
|
8473
|
+
}
|
|
8474
|
+
if (this._guardedVirtualizer && order.length > 0
|
|
8475
|
+
&& typeof this._guardedVirtualizer.computeWindow === 'function') {
|
|
8476
|
+
const viewportHeight = this._resolveGuardedViewportHeight();
|
|
8477
|
+
const index = this._guardedVirtualizer.computeWindow(scrollTop, viewportHeight).startIndex;
|
|
8478
|
+
const key = order[index] ?? null;
|
|
8479
|
+
if (key !== null) {
|
|
8480
|
+
return {
|
|
8481
|
+
key,
|
|
8482
|
+
offset: this._guardedVirtualizer.cumulativeOffset(index) - scrollTop,
|
|
8483
|
+
scrollTop,
|
|
8484
|
+
order,
|
|
8485
|
+
};
|
|
8486
|
+
}
|
|
8487
|
+
}
|
|
8488
|
+
return { key: null, offset: 0, scrollTop, order };
|
|
8489
|
+
}
|
|
8490
|
+
/** Restore the previous visible option only when this opening changed order. */
|
|
8491
|
+
_restorePreservedOptionsViewport() {
|
|
8492
|
+
const anchor = this._openOptionsViewportAnchor;
|
|
8493
|
+
this._openOptionsViewportAnchor = null;
|
|
8494
|
+
if (!anchor)
|
|
8495
|
+
return;
|
|
8496
|
+
const nextOrder = this._renderPlan.filteredKeys;
|
|
8497
|
+
const nextPositionByKey = new Map(nextOrder.map((key, index) => [key, index]));
|
|
8498
|
+
const orderChanged = anchor.order.some((key, oldIndex) => {
|
|
8499
|
+
const nextIndex = nextPositionByKey.get(key);
|
|
8500
|
+
return nextIndex !== undefined && nextIndex !== oldIndex;
|
|
8501
|
+
});
|
|
8502
|
+
if (!orderChanged)
|
|
8503
|
+
return;
|
|
8504
|
+
const scroller = this._optionsContainer;
|
|
8505
|
+
const viewportHeight = this._resolveGuardedViewportHeight() || scroller.clientHeight;
|
|
8506
|
+
let targetScrollTop = null;
|
|
8507
|
+
if (anchor.key !== null) {
|
|
8508
|
+
const displayIndex = this._renderPlan.displayIndexByKey.get(anchor.key);
|
|
8509
|
+
if (displayIndex !== undefined) {
|
|
8510
|
+
const sourceIndex = this._renderPlan.sourceIndexByKey.get(anchor.key);
|
|
8511
|
+
const option = sourceIndex === undefined ? null : this._getOptionElementByIndex(sourceIndex);
|
|
8512
|
+
const viewportTop = scroller.getBoundingClientRect().top + scroller.clientTop;
|
|
8513
|
+
const optionTop = option?.getBoundingClientRect().top;
|
|
8514
|
+
if (option && option.getBoundingClientRect().height > 0 && Number.isFinite(optionTop)) {
|
|
8515
|
+
targetScrollTop = scroller.scrollTop + optionTop - viewportTop - anchor.offset;
|
|
8516
|
+
}
|
|
8517
|
+
else if (this._guardedVirtualizer) {
|
|
8518
|
+
targetScrollTop = this._guardedVirtualizer.cumulativeOffset(displayIndex) - anchor.offset;
|
|
8519
|
+
}
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8522
|
+
if (targetScrollTop === null)
|
|
8523
|
+
targetScrollTop = anchor.scrollTop;
|
|
8524
|
+
let maxScrollTop = Number.POSITIVE_INFINITY;
|
|
8525
|
+
if (this._guardedVirtualizer) {
|
|
8526
|
+
maxScrollTop = Math.max(0, this._guardedVirtualizer.cumulativeOffset(nextOrder.length) - viewportHeight);
|
|
8527
|
+
}
|
|
8528
|
+
else if (scroller.scrollHeight > 0 && scroller.clientHeight > 0) {
|
|
8529
|
+
maxScrollTop = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
|
8530
|
+
}
|
|
8531
|
+
targetScrollTop = Math.max(0, Math.min(targetScrollTop, maxScrollTop));
|
|
8532
|
+
if (Math.abs(targetScrollTop - scroller.scrollTop) < 1)
|
|
8533
|
+
return;
|
|
8534
|
+
// The coordinator owns this single restoration write. The virtualizer may
|
|
8535
|
+
// update its mounted window in response, but it must not issue a second
|
|
8536
|
+
// physical positioning correction for this transaction.
|
|
8537
|
+
this._guardedVirtualScrollTop = targetScrollTop;
|
|
8538
|
+
scroller.scrollTop = targetScrollTop;
|
|
8539
|
+
}
|
|
8540
|
+
/** Used only when Element.getAnimations() is unavailable. */
|
|
8541
|
+
_getDropdownEntranceFallbackDurationMs() {
|
|
8542
|
+
if (window.matchMedia?.('(prefers-reduced-motion: reduce)').matches)
|
|
8543
|
+
return 0;
|
|
8544
|
+
const style = getComputedStyle(this._dropdown);
|
|
8545
|
+
const parseTime = (value) => {
|
|
8546
|
+
const trimmed = value.trim();
|
|
8547
|
+
const parsed = Number.parseFloat(trimmed);
|
|
8548
|
+
if (!Number.isFinite(parsed))
|
|
8549
|
+
return 0;
|
|
8550
|
+
return trimmed.endsWith('ms') ? parsed : trimmed.endsWith('s') ? parsed * 1000 : 0;
|
|
8551
|
+
};
|
|
8552
|
+
const animationDurations = style.animationDuration.split(',');
|
|
8553
|
+
const animationDelays = style.animationDelay.split(',');
|
|
8554
|
+
const animationIterations = style.animationIterationCount.split(',');
|
|
8555
|
+
const maxAnimation = Math.max(0, ...animationDurations.map((duration, index) => {
|
|
8556
|
+
const count = Number.parseFloat(animationIterations[index % animationIterations.length] ?? '1');
|
|
8557
|
+
if (!Number.isFinite(count))
|
|
8558
|
+
return 0;
|
|
8559
|
+
return parseTime(duration)
|
|
8560
|
+
* Math.max(0, count)
|
|
8561
|
+
+ parseTime(animationDelays[index % animationDelays.length] ?? '0s');
|
|
8562
|
+
}));
|
|
8563
|
+
const transitionDurations = style.transitionDuration.split(',');
|
|
8564
|
+
const transitionDelays = style.transitionDelay.split(',');
|
|
8565
|
+
const maxTransition = Math.max(0, ...transitionDurations.map((duration, index) => parseTime(duration) + parseTime(transitionDelays[index % transitionDelays.length] ?? '0s')));
|
|
8566
|
+
return Math.min(10000, Math.max(maxAnimation, maxTransition));
|
|
8567
|
+
}
|
|
7687
8568
|
/** Stop an outstanding exit before reopening, disconnecting or starting another one. */
|
|
7688
8569
|
_cancelDropdownExit() {
|
|
7689
8570
|
if (this._dropdownExitTimer !== null) {
|
|
@@ -7910,6 +8791,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
7910
8791
|
return results;
|
|
7911
8792
|
}
|
|
7912
8793
|
_handleSearch(query) {
|
|
8794
|
+
if (this._selectedLabelTooltipTrigger === this._input
|
|
8795
|
+
&& (query.length > 0 || this._getSelectedLabelForTrigger(this._input) === null)) {
|
|
8796
|
+
this._hideSelectedLabelTooltip();
|
|
8797
|
+
}
|
|
7913
8798
|
if (this._dataRequestCoordinator
|
|
7914
8799
|
&& (this._acknowledgedProjectionPending || this._acknowledgedProjectionSettling)) {
|
|
7915
8800
|
// Keep the committed query/generation stable until the accepted snapshot
|
|
@@ -8014,6 +8899,12 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8014
8899
|
}
|
|
8015
8900
|
}
|
|
8016
8901
|
_handleKeydown(e) {
|
|
8902
|
+
if (e.key === 'Escape' && !this._selectedLabelTooltip.hidden) {
|
|
8903
|
+
e.preventDefault();
|
|
8904
|
+
e.stopPropagation();
|
|
8905
|
+
this._dismissSelectedLabelTooltip();
|
|
8906
|
+
return;
|
|
8907
|
+
}
|
|
8017
8908
|
if (!this._config.enabled)
|
|
8018
8909
|
return;
|
|
8019
8910
|
switch (e.key) {
|
|
@@ -8038,26 +8929,38 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8038
8929
|
case 'Home':
|
|
8039
8930
|
e.preventDefault();
|
|
8040
8931
|
if (this._state.isOpen) {
|
|
8932
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
8933
|
+
this._moveToVisualBoundary('first', { shiftKey: e.shiftKey, toggleKey: e.ctrlKey || e.metaKey });
|
|
8934
|
+
break;
|
|
8935
|
+
}
|
|
8041
8936
|
const selectableIndices = this._getSelectableOptionIndices();
|
|
8042
8937
|
const firstIndex = selectableIndices[0];
|
|
8043
8938
|
if (firstIndex === undefined)
|
|
8044
8939
|
break;
|
|
8045
8940
|
this._setActive(firstIndex);
|
|
8046
8941
|
if (this._config.selection.mode === 'multi' && e.shiftKey) {
|
|
8047
|
-
|
|
8942
|
+
const targetKey = this._itemRegistry.indexToKey.get(firstIndex);
|
|
8943
|
+
if (targetKey !== undefined)
|
|
8944
|
+
this._selectKeyboardRange(this._rangeAnchorKey ?? targetKey, targetKey, { clear: !(e.ctrlKey || e.metaKey) });
|
|
8048
8945
|
}
|
|
8049
8946
|
}
|
|
8050
8947
|
break;
|
|
8051
8948
|
case 'End':
|
|
8052
8949
|
e.preventDefault();
|
|
8053
8950
|
if (this._state.isOpen) {
|
|
8951
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
8952
|
+
this._moveToVisualBoundary('last', { shiftKey: e.shiftKey, toggleKey: e.ctrlKey || e.metaKey });
|
|
8953
|
+
break;
|
|
8954
|
+
}
|
|
8054
8955
|
const selectableIndices = this._getSelectableOptionIndices();
|
|
8055
8956
|
const lastIndex = selectableIndices[selectableIndices.length - 1];
|
|
8056
8957
|
if (lastIndex === undefined)
|
|
8057
8958
|
break;
|
|
8058
8959
|
this._setActive(lastIndex);
|
|
8059
8960
|
if (this._config.selection.mode === 'multi' && e.shiftKey) {
|
|
8060
|
-
|
|
8961
|
+
const targetKey = this._itemRegistry.indexToKey.get(lastIndex);
|
|
8962
|
+
if (targetKey !== undefined)
|
|
8963
|
+
this._selectKeyboardRange(this._rangeAnchorKey ?? targetKey, targetKey, { clear: !(e.ctrlKey || e.metaKey) });
|
|
8061
8964
|
}
|
|
8062
8965
|
}
|
|
8063
8966
|
break;
|
|
@@ -8075,6 +8978,9 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8075
8978
|
break;
|
|
8076
8979
|
case 'Enter':
|
|
8077
8980
|
case ' ':
|
|
8981
|
+
if (e.key === ' ' && this._config.searchable && e.target === this._input) {
|
|
8982
|
+
break;
|
|
8983
|
+
}
|
|
8078
8984
|
e.preventDefault();
|
|
8079
8985
|
if (!this._state.isOpen) {
|
|
8080
8986
|
this._handleOpen();
|
|
@@ -8098,7 +9004,8 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8098
9004
|
break;
|
|
8099
9005
|
case 'a':
|
|
8100
9006
|
case 'A':
|
|
8101
|
-
if ((e.ctrlKey || e.metaKey) &&
|
|
9007
|
+
if ((e.ctrlKey || e.metaKey) && !e.altKey
|
|
9008
|
+
&& this._config.selection.mode === 'multi' && !this._config.searchable) {
|
|
8102
9009
|
e.preventDefault();
|
|
8103
9010
|
this._selectAll();
|
|
8104
9011
|
}
|
|
@@ -8112,6 +9019,26 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8112
9019
|
}
|
|
8113
9020
|
}
|
|
8114
9021
|
_moveActive(delta, opts) {
|
|
9022
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
9023
|
+
const model = this._getVisualNavigationModel();
|
|
9024
|
+
if (model.selectableKeys.length === 0)
|
|
9025
|
+
return;
|
|
9026
|
+
const activeKey = this._engine.state.activeKey;
|
|
9027
|
+
const currentPosition = activeKey === null ? undefined : model.selectablePositionByKey.get(activeKey);
|
|
9028
|
+
// Load-more is only requested after movement reaches the actual visual end.
|
|
9029
|
+
if (delta === 1 && currentPosition === model.selectableKeys.length - 1 && this._requestKeyboardLoadMore())
|
|
9030
|
+
return;
|
|
9031
|
+
const nextKey = resolveVisualMovement(model, activeKey, delta);
|
|
9032
|
+
if (nextKey === null)
|
|
9033
|
+
return;
|
|
9034
|
+
this._setActiveForVisualKey(nextKey);
|
|
9035
|
+
if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
|
|
9036
|
+
const anchorKey = this._rangeAnchorKey ?? activeKey ?? nextKey;
|
|
9037
|
+
this._rangeAnchorKey = anchorKey;
|
|
9038
|
+
this._selectKeyboardRange(anchorKey, nextKey, { clear: !opts.toggleKey });
|
|
9039
|
+
}
|
|
9040
|
+
return;
|
|
9041
|
+
}
|
|
8115
9042
|
const selectableIndices = this._getSelectableOptionIndices();
|
|
8116
9043
|
if (selectableIndices.length === 0)
|
|
8117
9044
|
return;
|
|
@@ -8133,13 +9060,89 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8133
9060
|
const next = selectableIndices[nextPosition];
|
|
8134
9061
|
this._setActive(next);
|
|
8135
9062
|
if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
|
|
8136
|
-
const
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
this.
|
|
9063
|
+
const nextKey = this._itemRegistry.indexToKey.get(next);
|
|
9064
|
+
if (nextKey === undefined)
|
|
9065
|
+
return;
|
|
9066
|
+
const anchorKey = this._rangeAnchorKey ?? (currentIndex >= 0 ? this._itemRegistry.indexToKey.get(currentIndex) : undefined) ?? nextKey;
|
|
9067
|
+
this._rangeAnchorKey = anchorKey;
|
|
9068
|
+
this._selectKeyboardRange(anchorKey, nextKey, { clear: !opts?.toggleKey });
|
|
9069
|
+
}
|
|
9070
|
+
}
|
|
9071
|
+
_usesSelectedFirstVisualOrder() {
|
|
9072
|
+
return this._selectedOptionsConfigAtOpen.placement === 'selected-first';
|
|
9073
|
+
}
|
|
9074
|
+
_getVisualNavigationModel() {
|
|
9075
|
+
this._ensureRegistryCurrent();
|
|
9076
|
+
return createVisualNavigationModel(this._renderPlan.filteredKeys, (key) => {
|
|
9077
|
+
const record = this._itemRegistry.keyToRecord.get(key);
|
|
9078
|
+
if (!record || record.disabled)
|
|
9079
|
+
return false;
|
|
9080
|
+
const option = this._getOptionElementByIndex(record.index);
|
|
9081
|
+
return option?.getAttribute('aria-disabled') !== 'true';
|
|
9082
|
+
});
|
|
9083
|
+
}
|
|
9084
|
+
_setActiveForVisualKey(key, reason = 'keyboard', options = {}) {
|
|
9085
|
+
const sourceIndex = this._renderPlan.sourceIndexByKey.get(key)
|
|
9086
|
+
?? this._itemRegistry.keyToIndex.get(key);
|
|
9087
|
+
if (sourceIndex === undefined)
|
|
9088
|
+
return;
|
|
9089
|
+
this._setActive(sourceIndex, reason, options);
|
|
9090
|
+
}
|
|
9091
|
+
_moveToVisualBoundary(boundary, opts) {
|
|
9092
|
+
const model = this._getVisualNavigationModel();
|
|
9093
|
+
const targetKey = resolveVisualBoundary(model, boundary);
|
|
9094
|
+
if (targetKey === null)
|
|
9095
|
+
return;
|
|
9096
|
+
const currentKey = this._engine.state.activeKey;
|
|
9097
|
+
this._setActiveForVisualKey(targetKey);
|
|
9098
|
+
if (this._config.selection.mode === 'multi' && opts?.shiftKey) {
|
|
9099
|
+
const anchorKey = this._rangeAnchorKey ?? currentKey ?? targetKey;
|
|
9100
|
+
this._rangeAnchorKey = anchorKey;
|
|
9101
|
+
this._selectKeyboardRange(anchorKey, targetKey, { clear: !opts.toggleKey });
|
|
9102
|
+
}
|
|
9103
|
+
}
|
|
9104
|
+
_selectKeyboardRange(anchorKey, targetKey, opts) {
|
|
9105
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
9106
|
+
const model = this._getVisualNavigationModel();
|
|
9107
|
+
const resolvedAnchor = model.selectablePositionByKey.has(anchorKey) ? anchorKey : targetKey;
|
|
9108
|
+
this._rangeAnchorKey = resolvedAnchor;
|
|
9109
|
+
this._selectVisualRange(resolvedAnchor, targetKey, opts);
|
|
9110
|
+
return;
|
|
8142
9111
|
}
|
|
9112
|
+
const start = this._itemRegistry.keyToIndex.get(anchorKey);
|
|
9113
|
+
const end = this._itemRegistry.keyToIndex.get(targetKey);
|
|
9114
|
+
if (start !== undefined && end !== undefined)
|
|
9115
|
+
this._selectRange(start, end, opts);
|
|
9116
|
+
}
|
|
9117
|
+
_selectVisualRange(anchorKey, targetKey, opts) {
|
|
9118
|
+
if (this._config.selection.mode !== 'multi')
|
|
9119
|
+
return;
|
|
9120
|
+
this._ensureRegistryCurrent();
|
|
9121
|
+
const model = this._getVisualNavigationModel();
|
|
9122
|
+
const rangeKeys = resolveVisualRange(model, anchorKey, targetKey);
|
|
9123
|
+
if (rangeKeys.length === 0)
|
|
9124
|
+
return;
|
|
9125
|
+
const selectedEntries = this._getSelectedEntries();
|
|
9126
|
+
const entries = opts?.clear
|
|
9127
|
+
? selectedEntries.filter((entry) => !this._itemRegistry.keyToRecord.has(entry.key))
|
|
9128
|
+
: selectedEntries;
|
|
9129
|
+
for (const key of rangeKeys) {
|
|
9130
|
+
const record = this._itemRegistry.keyToRecord.get(key);
|
|
9131
|
+
if (!record || this._isOptionSelectionBlocked(record.item))
|
|
9132
|
+
continue;
|
|
9133
|
+
entries.push(record);
|
|
9134
|
+
}
|
|
9135
|
+
this._requestSelectionReplacement(entries, opts?.reason ?? 'keyboard', 'select visual range');
|
|
9136
|
+
this._renderOptions();
|
|
9137
|
+
this._updateInputDisplay();
|
|
9138
|
+
const target = this._itemRegistry.keyToRecord.get(targetKey);
|
|
9139
|
+
const selectDetail = target ? this._getSelectEventDetail(target) : null;
|
|
9140
|
+
if (selectDetail)
|
|
9141
|
+
this._emit('select', selectDetail);
|
|
9142
|
+
this._emitChange();
|
|
9143
|
+
this._announce(`${this._state.selectedIndices.size} items selected`);
|
|
9144
|
+
if (selectDetail)
|
|
9145
|
+
this._config.callbacks.onSelect?.(selectDetail);
|
|
8143
9146
|
}
|
|
8144
9147
|
/** Return true only when boundary navigation is held for an in-flight/new page. */
|
|
8145
9148
|
_requestKeyboardLoadMore() {
|
|
@@ -8168,7 +9171,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8168
9171
|
this._dispatchAcknowledgedActions(actions);
|
|
8169
9172
|
return true;
|
|
8170
9173
|
}
|
|
8171
|
-
_setActive(index, reason = 'keyboard') {
|
|
9174
|
+
_setActive(index, reason = 'keyboard', options = {}) {
|
|
8172
9175
|
this._ensureRegistryCurrent();
|
|
8173
9176
|
const record = this._getRecordByIndex(index);
|
|
8174
9177
|
let option = this._getOptionElementByIndex(index);
|
|
@@ -8179,8 +9182,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8179
9182
|
if (!record || record.disabled || !option || option.getAttribute('aria-disabled') === 'true') {
|
|
8180
9183
|
return;
|
|
8181
9184
|
}
|
|
8182
|
-
if (reason === 'keyboard')
|
|
9185
|
+
if (reason === 'keyboard' || reason === 'search') {
|
|
8183
9186
|
this._keyboardActiveChangeGeneration += 1;
|
|
9187
|
+
this._cancelOpenSelectedScroll();
|
|
9188
|
+
}
|
|
8184
9189
|
const previousIndex = this._state.activeIndex;
|
|
8185
9190
|
this._dispatchActiveKey(record.key, reason, 'set active');
|
|
8186
9191
|
if (this._state.activeIndex !== index)
|
|
@@ -8207,8 +9212,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8207
9212
|
else {
|
|
8208
9213
|
this._syncCustomOptionActiveClasses(option, true);
|
|
8209
9214
|
}
|
|
8210
|
-
if (typeof option.scrollIntoView === 'function') {
|
|
8211
|
-
// Don't scroll wildly when just opening with pre-selections
|
|
9215
|
+
if (options.scroll !== false && typeof option.scrollIntoView === 'function') {
|
|
8212
9216
|
option.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
|
8213
9217
|
}
|
|
8214
9218
|
// Announce position for screen readers
|
|
@@ -8264,8 +9268,22 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8264
9268
|
this._typeTimeout = window.setTimeout(() => {
|
|
8265
9269
|
this._typeBuffer = '';
|
|
8266
9270
|
}, 500);
|
|
8267
|
-
//
|
|
9271
|
+
// Type-ahead uses the displayed candidate order when a presentation projection is active.
|
|
8268
9272
|
const getValue = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
|
|
9273
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
9274
|
+
const model = this._getVisualNavigationModel();
|
|
9275
|
+
const matchKey = model.selectableKeys.find((key) => {
|
|
9276
|
+
const record = this._itemRegistry.keyToRecord.get(key);
|
|
9277
|
+
return record !== undefined && getValue(record.item).toLowerCase().startsWith(this._typeBuffer);
|
|
9278
|
+
});
|
|
9279
|
+
if (matchKey !== undefined) {
|
|
9280
|
+
const sourceIndex = this._renderPlan.sourceIndexByKey.get(matchKey)
|
|
9281
|
+
?? this._itemRegistry.keyToIndex.get(matchKey);
|
|
9282
|
+
if (sourceIndex !== undefined)
|
|
9283
|
+
this._setActive(sourceIndex, 'search');
|
|
9284
|
+
}
|
|
9285
|
+
return;
|
|
9286
|
+
}
|
|
8269
9287
|
const matchIndex = this._state.loadedItems.findIndex((item) => getValue(item).toLowerCase().startsWith(this._typeBuffer));
|
|
8270
9288
|
if (matchIndex >= 0) {
|
|
8271
9289
|
this._setActive(matchIndex, 'search');
|
|
@@ -8334,6 +9352,17 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8334
9352
|
};
|
|
8335
9353
|
}
|
|
8336
9354
|
_setInitialActiveOption() {
|
|
9355
|
+
if (this._usesSelectedFirstVisualOrder()) {
|
|
9356
|
+
const model = this._getVisualNavigationModel();
|
|
9357
|
+
const selectedKey = model.selectableKeys.find((key) => this._engine.state.selectedKeys.has(key));
|
|
9358
|
+
if (selectedKey === undefined) {
|
|
9359
|
+
this._dispatchActiveKey(null, 'open', 'initial active option');
|
|
9360
|
+
return;
|
|
9361
|
+
}
|
|
9362
|
+
// Resolve via stable identity so the open-time projection remains authoritative.
|
|
9363
|
+
this._setActiveForVisualKey(selectedKey, 'open', { scroll: false });
|
|
9364
|
+
return;
|
|
9365
|
+
}
|
|
8337
9366
|
const selectableIndices = this._getSelectableOptionIndices();
|
|
8338
9367
|
const selected = Array.from(this._state.selectedIndices).sort((a, b) => a - b);
|
|
8339
9368
|
// Opening an empty select must not implicitly assign an active descendant.
|
|
@@ -8343,7 +9372,9 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8343
9372
|
return;
|
|
8344
9373
|
}
|
|
8345
9374
|
const target = selected.find((index) => selectableIndices.includes(index)) ?? selectableIndices[0];
|
|
8346
|
-
|
|
9375
|
+
// Set logical active state and ARIA immediately. The open-time coordinator
|
|
9376
|
+
// owns any physical positioning after the dropdown's entrance settles.
|
|
9377
|
+
this._setActive(target, 'open', { scroll: false });
|
|
8347
9378
|
}
|
|
8348
9379
|
_announce(message) {
|
|
8349
9380
|
const effects = computeAccessibilityEffects(deriveAccessibilityState(this._engine.state), {
|
|
@@ -8397,9 +9428,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8397
9428
|
const toggleKey = Boolean(opts?.toggleKey);
|
|
8398
9429
|
const shiftKey = Boolean(opts?.shiftKey);
|
|
8399
9430
|
if (shiftKey) {
|
|
8400
|
-
const
|
|
8401
|
-
|
|
8402
|
-
this.
|
|
9431
|
+
const targetKey = record.key;
|
|
9432
|
+
const anchorKey = this._rangeAnchorKey ?? targetKey;
|
|
9433
|
+
this._selectKeyboardRange(anchorKey, targetKey, { clear: !toggleKey, reason });
|
|
9434
|
+
this._rangeAnchorKey = anchorKey;
|
|
8403
9435
|
return;
|
|
8404
9436
|
}
|
|
8405
9437
|
// Multi select with toggle
|
|
@@ -8413,7 +9445,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8413
9445
|
// Re-render to update styles (safer than trying to find the element in filtered list)
|
|
8414
9446
|
this._renderOptions();
|
|
8415
9447
|
}
|
|
8416
|
-
this.
|
|
9448
|
+
this._rangeAnchorKey = record.key;
|
|
8417
9449
|
this._updateInputDisplay();
|
|
8418
9450
|
const selectDetail = this._getSelectEventDetail(record);
|
|
8419
9451
|
this._emit('select', selectDetail);
|
|
@@ -8444,7 +9476,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8444
9476
|
: null;
|
|
8445
9477
|
const hadFocusedChipRemove = focusedBadge !== null;
|
|
8446
9478
|
const focusedBadgeIndex = focusedBadge
|
|
8447
|
-
?
|
|
9479
|
+
? this._getActiveChipBadges().indexOf(focusedBadge)
|
|
8448
9480
|
: -1;
|
|
8449
9481
|
const option = this._itemRegistry.keyToRecord.has(entry.key)
|
|
8450
9482
|
? this._getOptionElementByIndex(entry.index)
|
|
@@ -8470,7 +9502,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8470
9502
|
this._renderOptions();
|
|
8471
9503
|
this._emitChange();
|
|
8472
9504
|
if (hadFocusedChipRemove && this.isConnected) {
|
|
8473
|
-
const removeButtons = this.
|
|
9505
|
+
const removeButtons = this._getActiveChipRemoveButtons();
|
|
8474
9506
|
if (removeButtons.length > 0) {
|
|
8475
9507
|
const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
|
|
8476
9508
|
removeButtons[nextFocusIndex].focus();
|
|
@@ -8484,8 +9516,248 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8484
9516
|
: undefined;
|
|
8485
9517
|
this._emit('remove', { item: config?.item ?? item, index: entry.index });
|
|
8486
9518
|
}
|
|
9519
|
+
_getActiveChipBadges() {
|
|
9520
|
+
return Array.from(this._inputContent.querySelectorAll('.selection-badge'))
|
|
9521
|
+
.filter((badge) => badge.dataset.motion !== 'exiting' && !badge.hasAttribute('inert'));
|
|
9522
|
+
}
|
|
9523
|
+
_getActiveChipRemoveButtons() {
|
|
9524
|
+
return this._getActiveChipBadges()
|
|
9525
|
+
.map((badge) => badge.querySelector('[part="chip-remove"]'))
|
|
9526
|
+
.filter((button) => button !== null && !button.disabled);
|
|
9527
|
+
}
|
|
9528
|
+
_clearChipPresentation() {
|
|
9529
|
+
const badges = new Set(this._chipElements.values());
|
|
9530
|
+
const tooltipTriggers = [
|
|
9531
|
+
this._selectedLabelTooltipTrigger,
|
|
9532
|
+
this._selectedLabelTooltipPointerTrigger,
|
|
9533
|
+
this._selectedLabelTooltipFocusTrigger,
|
|
9534
|
+
this._selectedLabelTooltipDismissedTrigger,
|
|
9535
|
+
];
|
|
9536
|
+
if (tooltipTriggers.some((trigger) => trigger !== null
|
|
9537
|
+
&& Array.from(badges).some((badge) => badge.contains(trigger)))) {
|
|
9538
|
+
this._hideSelectedLabelTooltip(true);
|
|
9539
|
+
}
|
|
9540
|
+
for (const [key, state] of this._chipExitStates) {
|
|
9541
|
+
window.clearTimeout(state.timer);
|
|
9542
|
+
this._chipExitStates.delete(key);
|
|
9543
|
+
state.animations.forEach((animation) => animation.cancel());
|
|
9544
|
+
}
|
|
9545
|
+
for (const badge of this._chipElements.values()) {
|
|
9546
|
+
badge.removeAttribute('inert');
|
|
9547
|
+
badge.remove();
|
|
9548
|
+
}
|
|
9549
|
+
this._chipExitStates.clear();
|
|
9550
|
+
this._chipElements.clear();
|
|
9551
|
+
}
|
|
9552
|
+
_cancelChipExit(key, badge) {
|
|
9553
|
+
const state = this._chipExitStates.get(key);
|
|
9554
|
+
if (!state || state.badge !== badge)
|
|
9555
|
+
return;
|
|
9556
|
+
window.clearTimeout(state.timer);
|
|
9557
|
+
this._chipExitStates.delete(key);
|
|
9558
|
+
state.animations.forEach((animation) => animation.cancel());
|
|
9559
|
+
badge.removeAttribute('data-motion');
|
|
9560
|
+
badge.removeAttribute('aria-hidden');
|
|
9561
|
+
badge.removeAttribute('inert');
|
|
9562
|
+
badge.setAttribute('part', 'chip');
|
|
9563
|
+
const removeButton = badge.querySelector('[part="chip-remove"]');
|
|
9564
|
+
if (removeButton)
|
|
9565
|
+
removeButton.disabled = false;
|
|
9566
|
+
}
|
|
9567
|
+
_finishChipExit(key, expected) {
|
|
9568
|
+
const state = this._chipExitStates.get(key);
|
|
9569
|
+
if (!state || state.badge !== expected)
|
|
9570
|
+
return;
|
|
9571
|
+
window.clearTimeout(state.timer);
|
|
9572
|
+
this._chipExitStates.delete(key);
|
|
9573
|
+
state.animations.forEach((animation) => {
|
|
9574
|
+
if (animation.playState !== 'finished')
|
|
9575
|
+
animation.cancel();
|
|
9576
|
+
});
|
|
9577
|
+
this._chipElements.delete(key);
|
|
9578
|
+
expected.remove();
|
|
9579
|
+
if (this.isConnected) {
|
|
9580
|
+
this._observeSelectedLabelTooltipTargets();
|
|
9581
|
+
this._refreshSelectedLabelTooltipMeasurements();
|
|
9582
|
+
}
|
|
9583
|
+
}
|
|
9584
|
+
_moveFocusOutOfChip(badge) {
|
|
9585
|
+
const activeElement = this._shadow.activeElement;
|
|
9586
|
+
if (!(activeElement instanceof HTMLElement) || !badge.contains(activeElement))
|
|
9587
|
+
return;
|
|
9588
|
+
const badges = this._getActiveChipBadges().filter((candidate) => candidate !== badge);
|
|
9589
|
+
const oldIndex = Array.from(this._inputContent.querySelectorAll('.selection-badge')).indexOf(badge);
|
|
9590
|
+
const buttons = badges
|
|
9591
|
+
.map((candidate) => candidate.querySelector('[part="chip-remove"]'))
|
|
9592
|
+
.filter((button) => button !== null && !button.disabled);
|
|
9593
|
+
const next = buttons[Math.min(Math.max(oldIndex, 0), buttons.length - 1)];
|
|
9594
|
+
if (next)
|
|
9595
|
+
next.focus({ preventScroll: true });
|
|
9596
|
+
else
|
|
9597
|
+
this._input.focus({ preventScroll: true });
|
|
9598
|
+
}
|
|
9599
|
+
_beginChipExit(key, badge) {
|
|
9600
|
+
if (this._chipExitStates.has(key))
|
|
9601
|
+
return;
|
|
9602
|
+
this._moveFocusOutOfChip(badge);
|
|
9603
|
+
const label = badge.querySelector('.selection-badge-label');
|
|
9604
|
+
if (label) {
|
|
9605
|
+
this._removeSelectedLabelTooltipDescription(label);
|
|
9606
|
+
label.tabIndex = -1;
|
|
9607
|
+
if (this._selectedLabelTooltipPointerTrigger === label)
|
|
9608
|
+
this._selectedLabelTooltipPointerTrigger = null;
|
|
9609
|
+
if (this._selectedLabelTooltipFocusTrigger === label)
|
|
9610
|
+
this._selectedLabelTooltipFocusTrigger = null;
|
|
9611
|
+
if (this._selectedLabelTooltipDismissedTrigger === label)
|
|
9612
|
+
this._selectedLabelTooltipDismissedTrigger = null;
|
|
9613
|
+
if (this._selectedLabelTooltipTrigger === label)
|
|
9614
|
+
this._hideSelectedLabelTooltip();
|
|
9615
|
+
}
|
|
9616
|
+
badge.dataset.motion = 'exiting';
|
|
9617
|
+
badge.setAttribute('aria-hidden', 'true');
|
|
9618
|
+
badge.setAttribute('inert', '');
|
|
9619
|
+
badge.setAttribute('part', 'chip-exiting');
|
|
9620
|
+
const removeButton = badge.querySelector('[part="chip-remove"]');
|
|
9621
|
+
if (removeButton)
|
|
9622
|
+
removeButton.disabled = true;
|
|
9623
|
+
// Force style resolution after the exiting part is exposed. This also
|
|
9624
|
+
// verifies that a consumer keyframe is actually available across Shadow DOM.
|
|
9625
|
+
badge.getBoundingClientRect();
|
|
9626
|
+
const animations = (typeof badge.getAnimations === 'function' ? badge.getAnimations() : []).filter((animation) => {
|
|
9627
|
+
const cssAnimation = animation;
|
|
9628
|
+
return typeof cssAnimation.animationName === 'string'
|
|
9629
|
+
&& cssAnimation.animationName !== 'none'
|
|
9630
|
+
&& animation.playState !== 'idle';
|
|
9631
|
+
});
|
|
9632
|
+
const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
9633
|
+
if (reducedMotion || animations.length === 0) {
|
|
9634
|
+
badge.removeAttribute('data-motion');
|
|
9635
|
+
this._chipExitStates.set(key, { badge, animations: [], timer: 0 });
|
|
9636
|
+
this._finishChipExit(key, badge);
|
|
9637
|
+
return;
|
|
9638
|
+
}
|
|
9639
|
+
const endTimes = animations.map((animation) => Number(animation.effect?.getComputedTiming().endTime ?? 0));
|
|
9640
|
+
const maxEndTime = Math.max(0, ...endTimes);
|
|
9641
|
+
const fallbackDelay = Math.min(Number.isFinite(maxEndTime) ? maxEndTime + 100 : 1000, 5000);
|
|
9642
|
+
const timer = window.setTimeout(() => this._finishChipExit(key, badge), fallbackDelay);
|
|
9643
|
+
this._chipExitStates.set(key, { badge, animations, timer });
|
|
9644
|
+
void Promise.allSettled(animations.map((animation) => animation.finished))
|
|
9645
|
+
.then(() => this._finishChipExit(key, badge));
|
|
9646
|
+
}
|
|
9647
|
+
_createChip(key) {
|
|
9648
|
+
const badge = document.createElement('span');
|
|
9649
|
+
badge.className = 'selection-badge';
|
|
9650
|
+
badge.setAttribute('part', 'chip');
|
|
9651
|
+
const label = document.createElement('span');
|
|
9652
|
+
label.className = 'selection-badge-label';
|
|
9653
|
+
label.setAttribute('part', 'chip-label');
|
|
9654
|
+
this._selectedLabelKeys.set(label, key);
|
|
9655
|
+
badge.appendChild(label);
|
|
9656
|
+
this._chipElements.set(key, badge);
|
|
9657
|
+
return badge;
|
|
9658
|
+
}
|
|
9659
|
+
_updateChip(key, index, item, badge) {
|
|
9660
|
+
const getLabel = this._config.serverSide.getLabelFromItem || ((value) => value?.label ?? String(value));
|
|
9661
|
+
const labelText = getLabel(item);
|
|
9662
|
+
badge.className = 'selection-badge';
|
|
9663
|
+
if (this._config.styles.classNames?.badge) {
|
|
9664
|
+
badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
|
|
9665
|
+
}
|
|
9666
|
+
badge.setAttribute('part', 'chip');
|
|
9667
|
+
badge.removeAttribute('aria-hidden');
|
|
9668
|
+
badge.removeAttribute('inert');
|
|
9669
|
+
badge.removeAttribute('data-motion');
|
|
9670
|
+
const label = badge.querySelector('.selection-badge-label');
|
|
9671
|
+
label.className = 'selection-badge-label';
|
|
9672
|
+
if (this._config.styles.classNames?.badgeLabel) {
|
|
9673
|
+
label.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
|
|
9674
|
+
}
|
|
9675
|
+
label.textContent = labelText;
|
|
9676
|
+
this._selectedLabelKeys.set(label, key);
|
|
9677
|
+
const shouldShowRemove = this._config.selection.showRemoveButton !== false;
|
|
9678
|
+
let removeButton = badge.querySelector('[part="chip-remove"]');
|
|
9679
|
+
if (!shouldShowRemove) {
|
|
9680
|
+
removeButton?.remove();
|
|
9681
|
+
return;
|
|
9682
|
+
}
|
|
9683
|
+
if (!removeButton) {
|
|
9684
|
+
removeButton = document.createElement('button');
|
|
9685
|
+
removeButton.type = 'button';
|
|
9686
|
+
removeButton.addEventListener('pointerdown', (event) => {
|
|
9687
|
+
event.stopPropagation();
|
|
9688
|
+
event.preventDefault();
|
|
9689
|
+
});
|
|
9690
|
+
removeButton.addEventListener('click', (event) => {
|
|
9691
|
+
event.stopPropagation();
|
|
9692
|
+
event.preventDefault();
|
|
9693
|
+
this._handleOptionRemove(index, key);
|
|
9694
|
+
});
|
|
9695
|
+
const removeIcon = document.createElement('span');
|
|
9696
|
+
removeIcon.className = 'badge-remove-icon';
|
|
9697
|
+
removeIcon.setAttribute('part', 'chip-remove-icon');
|
|
9698
|
+
removeButton.appendChild(removeIcon);
|
|
9699
|
+
badge.appendChild(removeButton);
|
|
9700
|
+
}
|
|
9701
|
+
removeButton.className = 'badge-remove';
|
|
9702
|
+
if (this._config.styles.classNames?.removeButton) {
|
|
9703
|
+
removeButton.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
|
|
9704
|
+
}
|
|
9705
|
+
if (this._config.styles.classNames?.badgeRemove) {
|
|
9706
|
+
removeButton.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
|
|
9707
|
+
}
|
|
9708
|
+
removeButton.setAttribute('part', 'chip-remove');
|
|
9709
|
+
removeButton.setAttribute('aria-label', `Remove ${labelText}`);
|
|
9710
|
+
removeButton.disabled = false;
|
|
9711
|
+
const removeIcon = removeButton.querySelector('[part="chip-remove-icon"]');
|
|
9712
|
+
removeIcon.className = 'badge-remove-icon';
|
|
9713
|
+
if (this._config.styles.classNames?.badgeRemoveIcon) {
|
|
9714
|
+
removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
|
|
9715
|
+
}
|
|
9716
|
+
this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
|
|
9717
|
+
}
|
|
9718
|
+
_renderSelectedChips(entries) {
|
|
9719
|
+
const selectedKeys = new Set(entries.map(({ key }) => key));
|
|
9720
|
+
for (const { key, index, item } of entries) {
|
|
9721
|
+
let badge = this._chipElements.get(key);
|
|
9722
|
+
if (!badge)
|
|
9723
|
+
badge = this._createChip(key);
|
|
9724
|
+
this._cancelChipExit(key, badge);
|
|
9725
|
+
this._updateChip(key, index, item, badge);
|
|
9726
|
+
}
|
|
9727
|
+
for (const [key, badge] of this._chipElements) {
|
|
9728
|
+
if (!selectedKeys.has(key))
|
|
9729
|
+
this._beginChipExit(key, badge);
|
|
9730
|
+
}
|
|
9731
|
+
// Do not move chips merely because another chip entered its exit period.
|
|
9732
|
+
// That keeps the exiting chip in its original layout slot while the active
|
|
9733
|
+
// sequence remains correct. Reorder only when selected-key order changed.
|
|
9734
|
+
const desiredBadges = entries
|
|
9735
|
+
.map(({ key }) => this._chipElements.get(key))
|
|
9736
|
+
.filter((badge) => badge !== undefined);
|
|
9737
|
+
const currentBadges = this._getActiveChipBadges();
|
|
9738
|
+
const orderChanged = desiredBadges.length !== currentBadges.length
|
|
9739
|
+
|| desiredBadges.some((badge, index) => badge !== currentBadges[index]);
|
|
9740
|
+
if (orderChanged) {
|
|
9741
|
+
let nextSibling = this._input;
|
|
9742
|
+
for (let index = desiredBadges.length - 1; index >= 0; index -= 1) {
|
|
9743
|
+
const badge = desiredBadges[index];
|
|
9744
|
+
if (badge.nextSibling !== nextSibling)
|
|
9745
|
+
this._inputContent.insertBefore(badge, nextSibling);
|
|
9746
|
+
nextSibling = badge;
|
|
9747
|
+
}
|
|
9748
|
+
}
|
|
9749
|
+
}
|
|
8487
9750
|
_updateInputDisplay() {
|
|
8488
9751
|
const selectedEntries = this._getSelectedEntries();
|
|
9752
|
+
const focusedElement = this._shadow.activeElement;
|
|
9753
|
+
const focusedSelectedKey = focusedElement?.classList.contains('selection-badge-label')
|
|
9754
|
+
? this._selectedLabelKeys.get(focusedElement) ?? null
|
|
9755
|
+
: null;
|
|
9756
|
+
const focusedBadge = focusedElement?.closest('.selection-badge');
|
|
9757
|
+
const focusedChipKey = focusedBadge
|
|
9758
|
+
? Array.from(this._chipElements.entries()).find(([, badge]) => badge === focusedBadge)?.[0] ?? null
|
|
9759
|
+
: null;
|
|
9760
|
+
const focusedBadgeIndex = focusedBadge ? this._getActiveChipBadges().indexOf(focusedBadge) : -1;
|
|
8489
9761
|
const selectedItems = selectedEntries.map(({ item }) => item);
|
|
8490
9762
|
const nextKeys = new Set(selectedEntries.map(({ key }) => key));
|
|
8491
9763
|
const previousKeys = this._lastRenderedChipKeys;
|
|
@@ -8501,73 +9773,27 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8501
9773
|
// Only a newly added selected key can initiate auto-scroll.
|
|
8502
9774
|
this._cancelLatestChipScroll();
|
|
8503
9775
|
const getLabel = this._config.serverSide.getLabelFromItem || ((item) => item?.label ?? String(item));
|
|
8504
|
-
if (
|
|
8505
|
-
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
9776
|
+
if (this._config.selection.mode === 'multi') {
|
|
9777
|
+
if (selectedItems.length === 0) {
|
|
9778
|
+
this._input.value = '';
|
|
9779
|
+
this._input.placeholder = this._config.placeholder || 'Select an option...';
|
|
9780
|
+
}
|
|
9781
|
+
else {
|
|
9782
|
+
this._input.value = '';
|
|
9783
|
+
this._input.placeholder = '';
|
|
9784
|
+
}
|
|
9785
|
+
this._renderSelectedChips(selectedEntries);
|
|
8513
9786
|
}
|
|
8514
9787
|
else {
|
|
8515
|
-
//
|
|
8516
|
-
this.
|
|
8517
|
-
|
|
8518
|
-
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
badge.className = 'selection-badge';
|
|
8525
|
-
if (this._config.styles.classNames?.badge) {
|
|
8526
|
-
badge.classList.add(...this._config.styles.classNames.badge.split(' ').filter(Boolean));
|
|
8527
|
-
}
|
|
8528
|
-
badge.setAttribute('part', 'chip');
|
|
8529
|
-
const badgeLabel = document.createElement('span');
|
|
8530
|
-
badgeLabel.className = 'selection-badge-label';
|
|
8531
|
-
if (this._config.styles.classNames?.badgeLabel) {
|
|
8532
|
-
badgeLabel.classList.add(...this._config.styles.classNames.badgeLabel.split(' ').filter(Boolean));
|
|
8533
|
-
}
|
|
8534
|
-
badgeLabel.setAttribute('part', 'chip-label');
|
|
8535
|
-
badgeLabel.textContent = getLabel(item);
|
|
8536
|
-
badge.appendChild(badgeLabel);
|
|
8537
|
-
// Add remove button to badge
|
|
8538
|
-
if (this._config.selection.showRemoveButton !== false) {
|
|
8539
|
-
const removeBtn = document.createElement('button');
|
|
8540
|
-
removeBtn.type = 'button';
|
|
8541
|
-
removeBtn.className = 'badge-remove';
|
|
8542
|
-
if (this._config.styles.classNames?.removeButton) {
|
|
8543
|
-
removeBtn.classList.add(...this._config.styles.classNames.removeButton.split(' ').filter(Boolean));
|
|
8544
|
-
}
|
|
8545
|
-
if (this._config.styles.classNames?.badgeRemove) {
|
|
8546
|
-
removeBtn.classList.add(...this._config.styles.classNames.badgeRemove.split(' ').filter(Boolean));
|
|
8547
|
-
}
|
|
8548
|
-
removeBtn.setAttribute('part', 'chip-remove');
|
|
8549
|
-
removeBtn.setAttribute('aria-label', `Remove ${getLabel(item)}`);
|
|
8550
|
-
const removeIcon = document.createElement('span');
|
|
8551
|
-
removeIcon.className = 'badge-remove-icon';
|
|
8552
|
-
if (this._config.styles.classNames?.badgeRemoveIcon) {
|
|
8553
|
-
removeIcon.classList.add(...this._config.styles.classNames.badgeRemoveIcon.split(' ').filter(Boolean));
|
|
8554
|
-
}
|
|
8555
|
-
removeIcon.setAttribute('part', 'chip-remove-icon');
|
|
8556
|
-
this._setIconContent(removeIcon, this._config.selection.removeButtonIcon, '×');
|
|
8557
|
-
removeBtn.appendChild(removeIcon);
|
|
8558
|
-
removeBtn.addEventListener('pointerdown', (e) => {
|
|
8559
|
-
e.stopPropagation();
|
|
8560
|
-
e.preventDefault();
|
|
8561
|
-
});
|
|
8562
|
-
removeBtn.addEventListener('click', (e) => {
|
|
8563
|
-
e.stopPropagation();
|
|
8564
|
-
e.preventDefault();
|
|
8565
|
-
this._handleOptionRemove(index, key);
|
|
8566
|
-
});
|
|
8567
|
-
badge.appendChild(removeBtn);
|
|
8568
|
-
}
|
|
8569
|
-
this._inputContent.insertBefore(badge, this._input);
|
|
8570
|
-
});
|
|
9788
|
+
// A mode switch ends visual exits immediately; a single-select has no chip presentation.
|
|
9789
|
+
this._clearChipPresentation();
|
|
9790
|
+
if (selectedItems.length === 0) {
|
|
9791
|
+
this._input.value = '';
|
|
9792
|
+
this._input.placeholder = this._config.placeholder || 'Select an option...';
|
|
9793
|
+
}
|
|
9794
|
+
else {
|
|
9795
|
+
this._input.value = getLabel(selectedItems[0]);
|
|
9796
|
+
}
|
|
8571
9797
|
}
|
|
8572
9798
|
// A query typed during an accepted-snapshot projection is a pending user
|
|
8573
9799
|
// intent, not part of the committed projection state. Keep it visible even
|
|
@@ -8575,14 +9801,60 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8575
9801
|
if (this._acknowledgedPendingSearchQuery !== null) {
|
|
8576
9802
|
this._input.value = this._acknowledgedPendingSearchQuery;
|
|
8577
9803
|
}
|
|
8578
|
-
//
|
|
8579
|
-
// remove/clear, config rerenders, and item refreshes are not scroll intents.
|
|
9804
|
+
// Preserve manual scrolling. Only a newly selected key can request auto-scroll.
|
|
8580
9805
|
if (this._config.selection.mode === 'multi') {
|
|
8581
9806
|
this._inputContent.scrollLeft = previousChipScrollLeft;
|
|
8582
9807
|
if (newlyAddedKey !== undefined)
|
|
8583
9808
|
this._scheduleLatestChipScroll(newlyAddedKey);
|
|
8584
9809
|
}
|
|
8585
9810
|
this._syncClearControlState();
|
|
9811
|
+
this._observeSelectedLabelTooltipTargets();
|
|
9812
|
+
this._refreshSelectedLabelTooltipMeasurements();
|
|
9813
|
+
if (focusedChipKey !== null && !nextKeys.has(focusedChipKey)) {
|
|
9814
|
+
const removeButtons = this._getActiveChipRemoveButtons();
|
|
9815
|
+
if (removeButtons.length > 0) {
|
|
9816
|
+
const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
|
|
9817
|
+
removeButtons[nextFocusIndex].focus({ preventScroll: true });
|
|
9818
|
+
}
|
|
9819
|
+
else {
|
|
9820
|
+
this._input.focus({ preventScroll: true });
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
else if (focusedChipKey !== null && focusedElement && !focusedElement.isConnected) {
|
|
9824
|
+
const badge = this._chipElements.get(focusedChipKey);
|
|
9825
|
+
const removeButton = badge?.querySelector('[part="chip-remove"]');
|
|
9826
|
+
if (removeButton && !removeButton.disabled)
|
|
9827
|
+
removeButton.focus({ preventScroll: true });
|
|
9828
|
+
else
|
|
9829
|
+
this._input.focus({ preventScroll: true });
|
|
9830
|
+
}
|
|
9831
|
+
else if (focusedSelectedKey !== null) {
|
|
9832
|
+
const replacement = this._getActiveChipBadges()
|
|
9833
|
+
.map((badge) => badge.querySelector('.selection-badge-label'))
|
|
9834
|
+
.find((label) => label && this._selectedLabelKeys.get(label) === focusedSelectedKey);
|
|
9835
|
+
if (!replacement) {
|
|
9836
|
+
const removeButtons = this._getActiveChipRemoveButtons();
|
|
9837
|
+
if (removeButtons.length > 0) {
|
|
9838
|
+
const nextFocusIndex = Math.min(Math.max(focusedBadgeIndex, 0), removeButtons.length - 1);
|
|
9839
|
+
removeButtons[nextFocusIndex].focus({ preventScroll: true });
|
|
9840
|
+
}
|
|
9841
|
+
else {
|
|
9842
|
+
this._input.focus({ preventScroll: true });
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9845
|
+
else if (this._isSelectedLabelTruncated(replacement)) {
|
|
9846
|
+
// The measurement pass assigns the tab stop before focus restoration.
|
|
9847
|
+
replacement.tabIndex = 0;
|
|
9848
|
+
replacement.focus({ preventScroll: true });
|
|
9849
|
+
}
|
|
9850
|
+
else {
|
|
9851
|
+
this._input.focus({ preventScroll: true });
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
if (this._selectedLabelTooltipFocusTrigger === this._input
|
|
9855
|
+
|| this._selectedLabelTooltipPointerTrigger === this._input) {
|
|
9856
|
+
this._showSelectedLabelTooltip(this._input);
|
|
9857
|
+
}
|
|
8586
9858
|
}
|
|
8587
9859
|
_cancelLatestChipScroll() {
|
|
8588
9860
|
this._latestChipScrollGeneration += 1;
|
|
@@ -8614,7 +9886,7 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8614
9886
|
const index = entries.findIndex((entry) => entry.key === key);
|
|
8615
9887
|
if (index < 0)
|
|
8616
9888
|
return;
|
|
8617
|
-
const chip = this.
|
|
9889
|
+
const chip = this._getActiveChipBadges()[index];
|
|
8618
9890
|
if (!chip)
|
|
8619
9891
|
return;
|
|
8620
9892
|
const hostBounds = this._inputContent.getBoundingClientRect();
|
|
@@ -8672,58 +9944,71 @@ class EnhancedSelect extends HTMLElement {
|
|
|
8672
9944
|
this._optionsContainer.style.transition = 'opacity 0.2s ease-in';
|
|
8673
9945
|
}, 150);
|
|
8674
9946
|
}
|
|
8675
|
-
_scrollToSelected() {
|
|
8676
|
-
|
|
8677
|
-
|
|
8678
|
-
|
|
8679
|
-
const
|
|
8680
|
-
if (
|
|
8681
|
-
return;
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
if (
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
// Find the selected item closest to viewport center
|
|
8689
|
-
let closestIndex = indices[0];
|
|
8690
|
-
let closestDistance = Infinity;
|
|
8691
|
-
for (const index of indices) {
|
|
8692
|
-
const option = this._getOptionElementByIndex(index);
|
|
8693
|
-
if (option) {
|
|
8694
|
-
const optionTop = option.offsetTop;
|
|
8695
|
-
const distance = Math.abs(optionTop - viewportCenter);
|
|
8696
|
-
if (distance < closestDistance) {
|
|
8697
|
-
closestDistance = distance;
|
|
8698
|
-
closestIndex = index;
|
|
8699
|
-
}
|
|
8700
|
-
}
|
|
8701
|
-
}
|
|
8702
|
-
targetIndex = closestIndex;
|
|
8703
|
-
}
|
|
8704
|
-
else {
|
|
8705
|
-
// For single select or only one selected item, use the configured target
|
|
8706
|
-
targetIndex = target === 'first' ? indices[0] : indices[indices.length - 1];
|
|
8707
|
-
}
|
|
8708
|
-
// Find and scroll to the target option
|
|
9947
|
+
_scrollToSelected(options = {}) {
|
|
9948
|
+
const config = options.config ?? this._config.scrollToSelected;
|
|
9949
|
+
if (!config.enabled)
|
|
9950
|
+
return;
|
|
9951
|
+
const targetKey = resolveSelectedTargetKey(this._renderPlan.filteredKeys, this._engine.state.selectedKeys, config.multiSelectTarget);
|
|
9952
|
+
if (targetKey === null)
|
|
9953
|
+
return;
|
|
9954
|
+
const targetIndex = this._renderPlan.sourceIndexByKey.get(targetKey)
|
|
9955
|
+
?? this._itemRegistry.keyToIndex.get(targetKey);
|
|
9956
|
+
if (targetIndex === undefined)
|
|
9957
|
+
return;
|
|
9958
|
+
// Resolve against the current eligible render plan first. A selected key
|
|
9959
|
+
// outside the filtered projection must never trigger materialization.
|
|
8709
9960
|
let option = this._getOptionElementByIndex(targetIndex);
|
|
8710
9961
|
if (!option && this._guardedVirtualizer) {
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
this._materializeGuardedVirtualKey(targetKey);
|
|
8714
|
-
option = this._getOptionElementByIndex(targetIndex);
|
|
8715
|
-
}
|
|
9962
|
+
this._materializeGuardedVirtualKey(targetKey);
|
|
9963
|
+
option = this._getOptionElementByIndex(targetIndex);
|
|
8716
9964
|
}
|
|
8717
9965
|
if (option) {
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
|
|
8723
|
-
});
|
|
9966
|
+
const reducedMotion = window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
9967
|
+
this._scrollOptionWithinOptionsContainer(option, config.block || 'nearest', reducedMotion && config.behavior === 'smooth' ? 'auto' : (config.behavior || 'smooth'), options.onlyIfNeeded === true);
|
|
9968
|
+
if (options.setActive !== false) {
|
|
9969
|
+
// Active/ARIA synchronization must not start a second physical scroll.
|
|
9970
|
+
this._setActive(targetIndex, 'programmatic', { scroll: false });
|
|
8724
9971
|
}
|
|
8725
|
-
|
|
8726
|
-
|
|
9972
|
+
}
|
|
9973
|
+
}
|
|
9974
|
+
_scrollOptionWithinOptionsContainer(option, block, behavior, onlyIfNeeded) {
|
|
9975
|
+
const scroller = this._optionsContainer;
|
|
9976
|
+
const scrollerRect = scroller.getBoundingClientRect();
|
|
9977
|
+
const viewportTop = scrollerRect.top + scroller.clientTop;
|
|
9978
|
+
const viewportBottom = viewportTop + scroller.clientHeight;
|
|
9979
|
+
const optionRect = option.getBoundingClientRect();
|
|
9980
|
+
if (onlyIfNeeded && optionRect.top >= viewportTop && optionRect.bottom <= viewportBottom)
|
|
9981
|
+
return;
|
|
9982
|
+
if (scroller.clientHeight <= 0 || optionRect.height <= 0)
|
|
9983
|
+
return;
|
|
9984
|
+
let targetScrollTop = scroller.scrollTop;
|
|
9985
|
+
if (block === 'start') {
|
|
9986
|
+
targetScrollTop += optionRect.top - viewportTop;
|
|
9987
|
+
}
|
|
9988
|
+
else if (block === 'center') {
|
|
9989
|
+
targetScrollTop += (optionRect.top + optionRect.bottom - viewportTop - viewportBottom) / 2;
|
|
9990
|
+
}
|
|
9991
|
+
else if (block === 'end') {
|
|
9992
|
+
targetScrollTop += optionRect.bottom - viewportBottom;
|
|
9993
|
+
}
|
|
9994
|
+
else if (optionRect.top < viewportTop) {
|
|
9995
|
+
targetScrollTop += optionRect.top - viewportTop;
|
|
9996
|
+
}
|
|
9997
|
+
else if (optionRect.bottom > viewportBottom) {
|
|
9998
|
+
targetScrollTop += optionRect.bottom - viewportBottom;
|
|
9999
|
+
}
|
|
10000
|
+
else {
|
|
10001
|
+
return;
|
|
10002
|
+
}
|
|
10003
|
+
const maxScrollTop = Math.max(0, scroller.scrollHeight - scroller.clientHeight);
|
|
10004
|
+
targetScrollTop = Math.max(0, Math.min(targetScrollTop, maxScrollTop));
|
|
10005
|
+
if (Math.abs(targetScrollTop - scroller.scrollTop) < 1)
|
|
10006
|
+
return;
|
|
10007
|
+
if (typeof scroller.scrollTo === 'function') {
|
|
10008
|
+
scroller.scrollTo({ top: targetScrollTop, behavior });
|
|
10009
|
+
}
|
|
10010
|
+
else {
|
|
10011
|
+
scroller.scrollTop = targetScrollTop;
|
|
8727
10012
|
}
|
|
8728
10013
|
}
|
|
8729
10014
|
async _loadMoreItems(trigger = 'manual') {
|
|
@@ -9209,10 +10494,21 @@ class EnhancedSelect extends HTMLElement {
|
|
|
9209
10494
|
this._invalidateGuardedMeasurements();
|
|
9210
10495
|
const previousMode = this._config.selection.mode;
|
|
9211
10496
|
const previousEnabled = this._config.enabled;
|
|
10497
|
+
const previousOpenScrollEnabled = this._config.scrollToSelected.enabled;
|
|
9212
10498
|
const previousDataLoadingConfig = this._dataLoadingConfig;
|
|
9213
10499
|
let searchEligibilityBecameInactive = false;
|
|
9214
|
-
const { dataLoading, callbacks, ...legacyConfig } = config;
|
|
10500
|
+
const { dataLoading, callbacks, selectedOptions, scrollToSelected, ...legacyConfig } = config;
|
|
9215
10501
|
const legacyUpdate = { ...legacyConfig };
|
|
10502
|
+
if (selectedOptions !== undefined) {
|
|
10503
|
+
const validation = validateSelectedOptionsConfig(selectedOptions);
|
|
10504
|
+
if (validation.valid)
|
|
10505
|
+
legacyUpdate.selectedOptions = validation.value;
|
|
10506
|
+
}
|
|
10507
|
+
if (scrollToSelected !== undefined) {
|
|
10508
|
+
const validation = validateScrollToSelectedConfig(scrollToSelected);
|
|
10509
|
+
if (validation.valid)
|
|
10510
|
+
legacyUpdate.scrollToSelected = validation.value;
|
|
10511
|
+
}
|
|
9216
10512
|
let configErrorDetail;
|
|
9217
10513
|
if (callbacks !== undefined && callbacks !== null) {
|
|
9218
10514
|
const callbackInput = callbacks;
|
|
@@ -9232,6 +10528,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
9232
10528
|
legacyUpdate.callbacks = legacyCallbacks;
|
|
9233
10529
|
}
|
|
9234
10530
|
this._config = this._mergeConfig(this._config, legacyUpdate);
|
|
10531
|
+
if (previousOpenScrollEnabled && !this._config.scrollToSelected.enabled) {
|
|
10532
|
+
this._openOptionsViewportAnchor = null;
|
|
10533
|
+
this._cancelOpenSelectedScroll();
|
|
10534
|
+
}
|
|
9235
10535
|
if (dataLoading !== undefined) {
|
|
9236
10536
|
const dataLoadingPrototype = dataLoading !== null && typeof dataLoading === 'object'
|
|
9237
10537
|
? Object.getPrototypeOf(dataLoading)
|
|
@@ -9778,19 +11078,39 @@ class EnhancedSelect extends HTMLElement {
|
|
|
9778
11078
|
activeKey: this._engine.state.activeKey,
|
|
9779
11079
|
};
|
|
9780
11080
|
}
|
|
9781
|
-
_createLegacyRenderPlan(filteredIndices) {
|
|
9782
|
-
const
|
|
9783
|
-
const
|
|
9784
|
-
.
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
11081
|
+
_createLegacyRenderPlan(filteredIndices, groupedPresentation = []) {
|
|
11082
|
+
const sourceIndices = [...filteredIndices];
|
|
11083
|
+
const sourceOrderedKeys = groupedPresentation.length > 0
|
|
11084
|
+
? groupedPresentation.flatMap((group) => group.orderedKeys)
|
|
11085
|
+
: sourceIndices
|
|
11086
|
+
.map((index) => this._itemRegistry.indexToKey.get(index))
|
|
11087
|
+
.filter((key) => key !== undefined);
|
|
11088
|
+
const shouldProjectSelectedFirst = this._usesSelectedFirstVisualOrder()
|
|
11089
|
+
&& groupedPresentation.length === 0;
|
|
11090
|
+
const selectedKeys = this._selectedOptionsSelectionAtOpen ?? this._engine.state.selectedKeys;
|
|
11091
|
+
const filteredKeys = shouldProjectSelectedFirst
|
|
11092
|
+
? projectSelectedOptionKeys(sourceOrderedKeys, selectedKeys)
|
|
11093
|
+
: sourceOrderedKeys;
|
|
11094
|
+
const indices = filteredKeys
|
|
11095
|
+
.map((key) => this._itemRegistry.keyToIndex.get(key))
|
|
11096
|
+
.filter((index) => index !== undefined);
|
|
11097
|
+
const displayIndexByKey = new Map();
|
|
11098
|
+
const sourceIndexByKey = new Map();
|
|
11099
|
+
filteredKeys.forEach((key, displayIndex) => {
|
|
11100
|
+
displayIndexByKey.set(key, displayIndex);
|
|
11101
|
+
const sourceIndex = this._itemRegistry.keyToIndex.get(key);
|
|
11102
|
+
if (sourceIndex !== undefined)
|
|
11103
|
+
sourceIndexByKey.set(key, sourceIndex);
|
|
11104
|
+
});
|
|
9788
11105
|
return {
|
|
9789
11106
|
mode: 'legacy-full',
|
|
9790
11107
|
filteredIndices: indices,
|
|
9791
11108
|
filteredKeys,
|
|
9792
11109
|
intendedRenderKeys: filteredKeys.slice(),
|
|
9793
|
-
|
|
11110
|
+
displayIndexByKey,
|
|
11111
|
+
sourceIndexByKey,
|
|
11112
|
+
filteredIndexByKey: displayIndexByKey,
|
|
11113
|
+
groupedPresentation,
|
|
9794
11114
|
};
|
|
9795
11115
|
}
|
|
9796
11116
|
_createVirtualRenderPlan(startIndex, endIndex) {
|
|
@@ -9799,12 +11119,16 @@ class EnhancedSelect extends HTMLElement {
|
|
|
9799
11119
|
const filteredIndices = intendedRenderKeys
|
|
9800
11120
|
.map((key) => this._itemRegistry.keyToIndex.get(key))
|
|
9801
11121
|
.filter((index) => index !== undefined);
|
|
11122
|
+
const displayIndexByKey = new Map(this._renderPlan.displayIndexByKey);
|
|
9802
11123
|
return {
|
|
9803
11124
|
mode: 'virtual-window',
|
|
9804
11125
|
filteredIndices,
|
|
9805
11126
|
filteredKeys,
|
|
9806
11127
|
intendedRenderKeys,
|
|
9807
|
-
|
|
11128
|
+
displayIndexByKey,
|
|
11129
|
+
sourceIndexByKey: new Map(this._renderPlan.sourceIndexByKey),
|
|
11130
|
+
filteredIndexByKey: displayIndexByKey,
|
|
11131
|
+
groupedPresentation: this._renderPlan.groupedPresentation,
|
|
9808
11132
|
};
|
|
9809
11133
|
}
|
|
9810
11134
|
_ensureGuardedVirtualizer(filteredKeys) {
|
|
@@ -10758,11 +12082,31 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10758
12082
|
// Handle Grouped Items Rendering (when no search query)
|
|
10759
12083
|
if (this._state.groupedItems.length > 0 && !query) {
|
|
10760
12084
|
this._destroyGuardedVirtualizer();
|
|
10761
|
-
|
|
12085
|
+
const groupedSource = this._state.groupedItems.map((group, groupIndex) => ({
|
|
12086
|
+
group,
|
|
12087
|
+
groupIndex,
|
|
12088
|
+
orderedKeys: group.options
|
|
12089
|
+
.map((item) => this._state.loadedItems.indexOf(item))
|
|
12090
|
+
.filter((index) => index >= 0)
|
|
12091
|
+
.map((index) => this._itemRegistry.indexToKey.get(index))
|
|
12092
|
+
.filter((key) => key !== undefined),
|
|
12093
|
+
}));
|
|
12094
|
+
const groupedOrder = this._usesSelectedFirstVisualOrder()
|
|
12095
|
+
? projectSelectedOptionGroups(groupedSource.map(({ groupIndex, orderedKeys }) => ({ groupIdentity: groupIndex, orderedKeys })), this._selectedOptionsSelectionAtOpen ?? this._engine.state.selectedKeys)
|
|
12096
|
+
: groupedSource.map(({ groupIndex, orderedKeys }) => ({ groupIdentity: groupIndex, orderedKeys }));
|
|
12097
|
+
const groupedPresentation = groupedOrder.map(({ groupIdentity, orderedKeys }) => ({
|
|
12098
|
+
group: this._state.groupedItems[groupIdentity],
|
|
12099
|
+
groupIndex: groupIdentity,
|
|
12100
|
+
orderedKeys,
|
|
12101
|
+
}));
|
|
12102
|
+
const groupedIndices = groupedPresentation.flatMap(({ orderedKeys }) => orderedKeys
|
|
12103
|
+
.map((key) => this._itemRegistry.keyToIndex.get(key))
|
|
12104
|
+
.filter((index) => index !== undefined));
|
|
12105
|
+
this._renderPlan = this._createLegacyRenderPlan(groupedIndices, groupedPresentation);
|
|
10762
12106
|
filteredIndicesForScope = this._renderPlan.filteredIndices;
|
|
10763
12107
|
this._registerShadowItems(filteredIndicesForScope);
|
|
10764
12108
|
this._refreshVirtualizationScope(filteredIndicesForScope);
|
|
10765
|
-
this.
|
|
12109
|
+
this._renderPlan.groupedPresentation.forEach(({ group, groupIndex, orderedKeys }) => {
|
|
10766
12110
|
let header;
|
|
10767
12111
|
if (this.groupHeaderRenderer) {
|
|
10768
12112
|
header = this.groupHeaderRenderer(group, groupIndex);
|
|
@@ -10788,10 +12132,10 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10788
12132
|
}
|
|
10789
12133
|
header.setAttribute('part', 'group-header');
|
|
10790
12134
|
this._optionsContainer.appendChild(header);
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
10794
|
-
|
|
12135
|
+
orderedKeys.forEach((key) => {
|
|
12136
|
+
const index = this._itemRegistry.keyToIndex.get(key);
|
|
12137
|
+
if (index !== undefined) {
|
|
12138
|
+
const item = this._state.loadedItems[index];
|
|
10795
12139
|
this._renderSingleOption(item, index, getValue, getLabel);
|
|
10796
12140
|
}
|
|
10797
12141
|
});
|
|
@@ -10860,13 +12204,16 @@ class EnhancedSelect extends HTMLElement {
|
|
|
10860
12204
|
const chunkSize = 80;
|
|
10861
12205
|
let cursor = 0;
|
|
10862
12206
|
let maxRenderTarget = 0;
|
|
10863
|
-
if (this._state.
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
|
|
10867
|
-
|
|
10868
|
-
|
|
10869
|
-
|
|
12207
|
+
if (this._state.isOpen
|
|
12208
|
+
&& this._config.scrollToSelected.enabled
|
|
12209
|
+
&& this._scrollToSelectedConfigAtOpen.enabled
|
|
12210
|
+
&& this._scrollToSelectedConfigAtOpen.onOpen !== 'preserve') {
|
|
12211
|
+
const targetKey = resolveSelectedTargetKey(this._renderPlan.filteredKeys, this._engine.state.selectedKeys, this._scrollToSelectedConfigAtOpen.multiSelectTarget);
|
|
12212
|
+
const targetPosition = targetKey === null
|
|
12213
|
+
? undefined
|
|
12214
|
+
: this._renderPlan.displayIndexByKey.get(targetKey);
|
|
12215
|
+
if (targetPosition !== undefined)
|
|
12216
|
+
maxRenderTarget = targetPosition + 20;
|
|
10870
12217
|
}
|
|
10871
12218
|
const renderChunk = () => {
|
|
10872
12219
|
if (renderCycleId !== this._renderCycleId) {
|
|
@@ -12316,5 +13663,5 @@ function warnCSPViolation(feature, fallback) {
|
|
|
12316
13663
|
}
|
|
12317
13664
|
}
|
|
12318
13665
|
|
|
12319
|
-
export { CSPFeatures, CustomOptionPool, DOMPool, DefaultSelectEffectRunner, EnhancedSelect, FenwickTree, NativeSelectElement, OptionRenderer, PerformanceTelemetry, SelectEngineBridge, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, applySelectionRequest, arrayIncludesValue, arraysEqualByValue, configureSelect, containsSuspiciousPatterns, createDefaultItemAdapter, createElement, createInitialSelectState, createItemRegistry, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getActiveKey, getCustomProperty, getDefaultDuplicateKeyPolicy, getHTMLSanitizer, getSelectedKeys, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, hasSelection, injectShadowStyles, isDisabled, isFocused, isOpen, isRegisteredKey, isSelected, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, transition, validateDataLoadingConfig, validateTemplate, valuesEqual, warnCSPViolation };
|
|
13666
|
+
export { CSPFeatures, CustomOptionPool, DOMPool, DefaultSelectEffectRunner, EnhancedSelect, FenwickTree, NativeSelectElement, OptionRenderer, PerformanceTelemetry, SelectEngineBridge, SelectOption, Virtualizer, WorkerManager, applyClasses, applyDefaultTheme, applySelectionRequest, arrayIncludesValue, arraysEqualByValue, configureSelect, containsSuspiciousPatterns, createDefaultItemAdapter, createElement, createInitialSelectState, createItemRegistry, createRendererHelpers, createTextNode, defaultTheme, detectEnvironment, escapeAttribute, escapeHTML, getActiveKey, getCustomProperty, getDefaultDuplicateKeyPolicy, getHTMLSanitizer, getSelectedKeys, getTelemetry, getWorkerManager, hasOverflowHiddenAncestor, hasSelection, injectShadowStyles, isDisabled, isFocused, isOpen, isRegisteredKey, isSelected, measureAsync, measureSync, removeCustomProperty, renderTemplate, resetSelectConfig, sanitizeHTML, selectConfig, setCSSProperties, setCustomProperties, setHTMLSanitizer, setTextContent, shadowDOMStyles, toggleClass, transition, validateDataLoadingConfig, validateScrollToSelectedConfig, validateSelectedOptionsConfig, validateSelectedOptionsConfigUpdate, validateTemplate, valuesEqual, warnCSPViolation };
|
|
12320
13667
|
//# sourceMappingURL=index.js.map
|