@aurodesignsystem/auro-formkit 6.0.2 → 6.0.3
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/CHANGELOG.md +8 -10
- package/components/checkbox/demo/customize.min.js +1 -1
- package/components/checkbox/demo/getting-started.min.js +20 -1
- package/components/checkbox/demo/index.min.js +1 -1
- package/components/checkbox/dist/index.js +1 -1
- package/components/checkbox/dist/registered.js +1 -1
- package/components/combobox/demo/customize.md +40 -0
- package/components/combobox/demo/customize.min.js +390 -56
- package/components/combobox/demo/getting-started.min.js +390 -56
- package/components/combobox/demo/index.html +1 -1
- package/components/combobox/demo/index.min.js +390 -56
- package/components/combobox/dist/index.js +68 -29
- package/components/combobox/dist/registered.js +68 -29
- package/components/counter/demo/customize.min.js +38 -3
- package/components/counter/demo/index.min.js +12 -3
- package/components/counter/dist/index.js +12 -3
- package/components/counter/dist/registered.js +12 -3
- package/components/datepicker/demo/customize.min.js +49 -5
- package/components/datepicker/demo/index.min.js +14 -5
- package/components/datepicker/dist/index.js +14 -5
- package/components/datepicker/dist/registered.js +14 -5
- package/components/dropdown/demo/customize.md +4 -4
- package/components/dropdown/demo/customize.min.js +53 -5
- package/components/dropdown/demo/getting-started.html +3 -0
- package/components/dropdown/demo/getting-started.md +4 -4
- package/components/dropdown/demo/getting-started.min.js +13087 -77
- package/components/dropdown/demo/index.min.js +30 -11
- package/components/dropdown/dist/index.js +10 -1
- package/components/dropdown/dist/registered.js +10 -1
- package/components/form/demo/customize.min.js +430 -69
- package/components/form/demo/getting-started.min.js +430 -69
- package/components/form/demo/index.min.js +430 -69
- package/components/form/demo/registerDemoDeps.min.js +430 -69
- package/components/input/demo/customize.min.js +1 -1
- package/components/input/demo/getting-started.min.js +1 -1
- package/components/input/demo/index.min.js +1 -1
- package/components/input/dist/index.js +1 -1
- package/components/input/dist/registered.js +1 -1
- package/components/menu/demo/customize.md +50 -0
- package/components/menu/demo/index.min.js +322 -27
- package/components/menu/dist/auro-menu-utils.d.ts +30 -0
- package/components/menu/dist/auro-menu.d.ts +23 -0
- package/components/menu/dist/index.js +322 -27
- package/components/menu/dist/registered.js +322 -27
- package/components/radio/demo/customize.min.js +1 -1
- package/components/radio/demo/getting-started.min.js +1 -1
- package/components/radio/demo/index.min.js +1 -1
- package/components/radio/dist/index.js +1 -1
- package/components/radio/dist/registered.js +1 -1
- package/components/select/demo/customize.md +72 -0
- package/components/select/demo/customize.min.js +333 -29
- package/components/select/demo/getting-started.min.js +333 -29
- package/components/select/demo/index.min.js +333 -29
- package/components/select/dist/index.js +11 -2
- package/components/select/dist/registered.js +11 -2
- package/custom-elements.json +1613 -1510
- package/package.json +1 -1
|
@@ -238,6 +238,116 @@ function isSelectableByValue(option) {
|
|
|
238
238
|
!option.hasAttribute('static');
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/* eslint-disable no-underscore-dangle */
|
|
242
|
+
/**
|
|
243
|
+
* Resolves the single selected option for a given `value`, preferring the
|
|
244
|
+
* option tracked by `selectedKey` (a user-initiated selection) over a
|
|
245
|
+
* first-by-value match. When multiple options share the same `value`, matching
|
|
246
|
+
* by `value` alone cannot distinguish which one the user picked; the key
|
|
247
|
+
* disambiguates it.
|
|
248
|
+
*
|
|
249
|
+
* The key is trusted only when it still resolves to an option whose `value`
|
|
250
|
+
* matches the requested `value`. If the key is stale (option removed) or the
|
|
251
|
+
* value was changed programmatically, resolution falls back to value matching —
|
|
252
|
+
* preserving backward-compatible behavior for preselection and `selectByValue`.
|
|
253
|
+
* @private
|
|
254
|
+
* @param {Array<HTMLElement>} items - The menu's flat option list.
|
|
255
|
+
* @param {string} value - The value to resolve.
|
|
256
|
+
* @param {string|undefined} selectedKey - The `_optionKey` of the user-selected option, if any.
|
|
257
|
+
* @returns {HTMLElement|undefined} The resolved option, or undefined when none match.
|
|
258
|
+
*/
|
|
259
|
+
function resolveSelectedOption(items, value, selectedKey) {
|
|
260
|
+
if (!items) {
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (selectedKey !== undefined) {
|
|
265
|
+
const keyed = items.find((item) => item._optionKey === selectedKey);
|
|
266
|
+
if (keyed && isSelectableByValue(keyed) && keyed.value === value) {
|
|
267
|
+
return keyed;
|
|
268
|
+
}
|
|
269
|
+
// Key exists but the option is gone or its value no longer matches — fall
|
|
270
|
+
// through to value-based matching.
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return items.find((item) => isSelectableByValue(item) && item.value === value);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Resolves the selected options for a multi-select `value` array, preferring
|
|
278
|
+
* options tracked by `selectedKeys` (user-initiated selections) and falling
|
|
279
|
+
* back to value matching for any values not resolved by key. The result is
|
|
280
|
+
* always sorted into DOM order regardless of selection sequence.
|
|
281
|
+
* @private
|
|
282
|
+
* @param {Array<HTMLElement>} items - The menu's flat option list.
|
|
283
|
+
* @param {Array<string>} valueArray - The selected values.
|
|
284
|
+
* @param {Array<string>|undefined} selectedKeys - The `_optionKey`s of the user-selected options, if any.
|
|
285
|
+
* @returns {Array<HTMLElement>} The resolved options in DOM order.
|
|
286
|
+
*/
|
|
287
|
+
function resolveSelectedOptions(items, valueArray, selectedKeys) {
|
|
288
|
+
if (!items) {
|
|
289
|
+
return [];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const resolved = [];
|
|
293
|
+
// Mirror `resolved` as a Set for O(1) membership checks below, matching the
|
|
294
|
+
// indexMap optimization used for the sort rather than scanning `resolved`
|
|
295
|
+
// on every candidate.
|
|
296
|
+
const resolvedSet = new Set();
|
|
297
|
+
|
|
298
|
+
// Track how many of each value are still available to resolve. A value that
|
|
299
|
+
// appears N times in `valueArray` may be satisfied at most N times total across
|
|
300
|
+
// the key pass and the value fallback below — matching by count, not presence,
|
|
301
|
+
// on BOTH passes. This stops a duplicate value from being over-resolved: e.g.
|
|
302
|
+
// two keyed options that both carry `SEA` cannot both match a single requested
|
|
303
|
+
// `SEA` (which happens when `value` is set directly without clearing
|
|
304
|
+
// `_selectedKey`, so more keys survive than the value set now asks for).
|
|
305
|
+
const remaining = new Map();
|
|
306
|
+
valueArray.forEach((val) => remaining.set(val, (remaining.get(val) || 0) + 1));
|
|
307
|
+
|
|
308
|
+
// Resolve by key first: trust a key only when its option is still selectable
|
|
309
|
+
// and there is still an unmatched occurrence of its value in the request set.
|
|
310
|
+
if (Array.isArray(selectedKeys)) {
|
|
311
|
+
selectedKeys.forEach((key) => {
|
|
312
|
+
const keyed = items.find((item) => item._optionKey === key);
|
|
313
|
+
if (keyed && isSelectableByValue(keyed) && (remaining.get(keyed.value) || 0) > 0 && !resolvedSet.has(keyed)) {
|
|
314
|
+
resolved.push(keyed);
|
|
315
|
+
resolvedSet.add(keyed);
|
|
316
|
+
remaining.set(keyed.value, remaining.get(keyed.value) - 1);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Fall back to value matching for the occurrences not resolved by key. Iterate
|
|
322
|
+
// the leftover per-value counts so a value that appears twice but was only
|
|
323
|
+
// resolved once by key still matches its remaining occurrence(s).
|
|
324
|
+
remaining.forEach((count, val) => {
|
|
325
|
+
for (let occurrence = 0; occurrence < count; occurrence += 1) {
|
|
326
|
+
const option = items.find((item) => isSelectableByValue(item) && item.value === val && !resolvedSet.has(item));
|
|
327
|
+
if (option) {
|
|
328
|
+
resolved.push(option);
|
|
329
|
+
resolvedSet.add(option);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// Always return in DOM order so display is consistent regardless of the order
|
|
335
|
+
// keys/values were selected. Every resolved option came from `items`, so an
|
|
336
|
+
// O(1) index lookup mirrors `_sortSelectedByDomOrder` and avoids the O(n)
|
|
337
|
+
// `items.indexOf` per comparison for large combobox option sets. Any element
|
|
338
|
+
// not in `items` (a stale snapshot from a future caller) sorts to the END via
|
|
339
|
+
// `?? items.length`, matching `_sortSelectedByDomOrder` and avoiding NaN
|
|
340
|
+
// comparisons.
|
|
341
|
+
const indexMap = new Map(items.map((item, index) => [
|
|
342
|
+
item,
|
|
343
|
+
index
|
|
344
|
+
]));
|
|
345
|
+
resolved.sort((optionA, optionB) => (indexMap.get(optionA) ?? items.length) - (indexMap.get(optionB) ?? items.length));
|
|
346
|
+
|
|
347
|
+
return resolved;
|
|
348
|
+
}
|
|
349
|
+
/* eslint-enable no-underscore-dangle */
|
|
350
|
+
|
|
241
351
|
/**
|
|
242
352
|
* Helper method to dispatch custom events.
|
|
243
353
|
* @param {HTMLElement} element - Element to dispatch event from.
|
|
@@ -263,6 +373,14 @@ function dispatchMenuEvent(element, eventName, detail = null) {
|
|
|
263
373
|
// See LICENSE in the project root for license information.
|
|
264
374
|
|
|
265
375
|
|
|
376
|
+
/**
|
|
377
|
+
* Monotonically increasing counter used to give each menu instance a unique
|
|
378
|
+
* `_menuInstanceId` prefix. Auto-generating the id (rather than using a random
|
|
379
|
+
* string) keeps option keys deterministic and collision-free across menus.
|
|
380
|
+
* @private
|
|
381
|
+
*/
|
|
382
|
+
let menuInstanceIdCounter = 0;
|
|
383
|
+
|
|
266
384
|
|
|
267
385
|
/**
|
|
268
386
|
* The `auro-menu` element provides users a way to select from a list of options.
|
|
@@ -334,9 +452,8 @@ class AuroMenu extends AuroElement {
|
|
|
334
452
|
|
|
335
453
|
// Instance properties (non-reactive)
|
|
336
454
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
*/
|
|
455
|
+
menuInstanceIdCounter += 1;
|
|
456
|
+
|
|
340
457
|
Object.assign(this, {
|
|
341
458
|
// Root-level menu (true) or a nested submenu (false)
|
|
342
459
|
rootMenu: true,
|
|
@@ -346,6 +463,21 @@ class AuroMenu extends AuroElement {
|
|
|
346
463
|
nestingSpacer: '<span class="nestingSpacer"></span>',
|
|
347
464
|
// Loading indicator for slot elements
|
|
348
465
|
loadingSlots: null,
|
|
466
|
+
// Unique id for this menu instance; prefixes every auto-generated option
|
|
467
|
+
// key so keys never collide across menus in the same document.
|
|
468
|
+
_menuInstanceId: `menu-${menuInstanceIdCounter}`,
|
|
469
|
+
// Monotonically increasing counter for option key generation. Never
|
|
470
|
+
// resets, so a key is never reused within this instance's lifetime.
|
|
471
|
+
_optionKeyCounter: 0,
|
|
472
|
+
// Key(s) of the option(s) the user has actively selected. A single string
|
|
473
|
+
// in single-select, an array in multi-select, undefined when nothing is
|
|
474
|
+
// user-selected. Used to disambiguate options that share a `value`.
|
|
475
|
+
_selectedKey: undefined,
|
|
476
|
+
// True only for the one updated() cycle following a user selection, so
|
|
477
|
+
// reconciliation trusts `_selectedKey`. A `value` change from a consumer's
|
|
478
|
+
// direct property assignment leaves this false, dropping the stale key so
|
|
479
|
+
// reconciliation falls back to first-by-value (see updated()).
|
|
480
|
+
_valueChangeFromSelection: false,
|
|
349
481
|
});
|
|
350
482
|
}
|
|
351
483
|
|
|
@@ -565,6 +697,13 @@ class AuroMenu extends AuroElement {
|
|
|
565
697
|
return;
|
|
566
698
|
}
|
|
567
699
|
|
|
700
|
+
// A programmatic value set carries no positional intent, so drop any
|
|
701
|
+
// `_selectedKey` left over from a prior user click. This makes reconciliation
|
|
702
|
+
// in updated() fall back to first-by-value (single) / value-in-DOM-order
|
|
703
|
+
// (multi), matching the documented contract for programmatic selection even
|
|
704
|
+
// when a stale key would still resolve to a duplicate-value option.
|
|
705
|
+
this._selectedKey = undefined;
|
|
706
|
+
|
|
568
707
|
// `value` is a String property; stringify arrays so attribute reflection and `formattedValue` parsing stay correct.
|
|
569
708
|
this.value = Array.isArray(value) ? JSON.stringify(value) : value;
|
|
570
709
|
}
|
|
@@ -612,6 +751,17 @@ class AuroMenu extends AuroElement {
|
|
|
612
751
|
updated(changedProperties) {
|
|
613
752
|
super.updated(changedProperties);
|
|
614
753
|
|
|
754
|
+
// Consume the selection-driven flag for THIS cycle up front. Clearing it
|
|
755
|
+
// unconditionally — not only inside the `value` branch below — prevents it
|
|
756
|
+
// from lingering `true` when a selection produces a serialized `value`
|
|
757
|
+
// byte-identical to the current one, in which case Lit schedules no
|
|
758
|
+
// `value`-change cycle to consume it. A lingering flag would misclassify a
|
|
759
|
+
// later consumer's programmatic `value` set as selection-driven and keep a
|
|
760
|
+
// stale `_selectedKey`. The reconcile path below re-sets the instance flag
|
|
761
|
+
// after this point, so its intentional cross-cycle hand-off still works.
|
|
762
|
+
const valueChangeFromSelection = this._valueChangeFromSelection;
|
|
763
|
+
this._valueChangeFromSelection = false;
|
|
764
|
+
|
|
615
765
|
// Single source of truth for 'auroMenu-selectedOption'. Selection handlers
|
|
616
766
|
// mutate optionSelected and let Lit's update cycle dispatch here; the prior
|
|
617
767
|
// .value comparison missed multi-select array changes and combined with the
|
|
@@ -635,6 +785,17 @@ class AuroMenu extends AuroElement {
|
|
|
635
785
|
this.initItems();
|
|
636
786
|
}
|
|
637
787
|
|
|
788
|
+
// Distinguish a selection-driven `value` change (a user click, which set
|
|
789
|
+
// the flag in handleSelectState / _sortSelectedByDomOrder) from a
|
|
790
|
+
// programmatic assignment by a consumer. A programmatic set carries no
|
|
791
|
+
// positional intent, so drop any leftover `_selectedKey` and let
|
|
792
|
+
// reconciliation fall back to first-by-value (single) / value-in-DOM-order
|
|
793
|
+
// (multi) — the same contract selectByValue() guarantees, even when a
|
|
794
|
+
// stale key would otherwise still resolve to a duplicate-value option.
|
|
795
|
+
if (!valueChangeFromSelection) {
|
|
796
|
+
this._selectedKey = undefined;
|
|
797
|
+
}
|
|
798
|
+
|
|
638
799
|
// Set when reconciliation reassigns `value` below. That reassignment schedules a
|
|
639
800
|
// second updated() cycle, so the `event`-attribute dispatch is deferred to that
|
|
640
801
|
// cycle to avoid firing option custom events twice on the same selection.
|
|
@@ -652,19 +813,55 @@ class AuroMenu extends AuroElement {
|
|
|
652
813
|
// Defensive default: `formattedValue` can be undefined for unexpected value types,
|
|
653
814
|
// and calling `.includes` on undefined would throw during reconciliation.
|
|
654
815
|
const valueArray = this.formattedValue || [];
|
|
655
|
-
|
|
816
|
+
// Resolve by key first (the user's exact picks), then fall back to
|
|
817
|
+
// value matching for any values not resolved by key — so pre-selection
|
|
818
|
+
// and programmatic value sets keep working. Result is DOM-ordered.
|
|
819
|
+
const matchingOptions = resolveSelectedOptions(this.items, valueArray, this._selectedKey);
|
|
656
820
|
newSelected = matchingOptions.length > 0 ? matchingOptions : undefined;
|
|
657
821
|
|
|
658
|
-
// Reconcile `value` with the selectable set.
|
|
659
|
-
// loaded but
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
822
|
+
// Reconcile `value` with the selectable set. An occurrence is dropped
|
|
823
|
+
// only when it is loaded but no selectable option can satisfy it —
|
|
824
|
+
// every loaded item sharing that value is non-selectable, or the value
|
|
825
|
+
// recurs more often than it has selectable options (a duplicate value
|
|
826
|
+
// whose extra siblings are disabled/static). This is count-based, not
|
|
827
|
+
// presence-based, so an enabled option is kept even when a disabled
|
|
828
|
+
// sibling shares its value — mirroring how `resolveSelectedOptions`
|
|
829
|
+
// resolves the same set. Entries with no matching item yet are
|
|
830
|
+
// preserved so async preselection still works, and the toggle handlers
|
|
831
|
+
// rebuild `value` from `formattedValue`, so a rejected entry cannot
|
|
832
|
+
// resurface on the next select/deselect.
|
|
833
|
+
const selectableByValue = new Map();
|
|
834
|
+
const loadedValues = new Set();
|
|
835
|
+
if (this.items) {
|
|
836
|
+
this.items.forEach((item) => {
|
|
837
|
+
loadedValues.add(item.value);
|
|
838
|
+
if (isSelectableByValue(item)) {
|
|
839
|
+
selectableByValue.set(item.value, (selectableByValue.get(item.value) || 0) + 1);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
const reconciled = valueArray.filter((val) => {
|
|
845
|
+
// Not loaded yet (async preselection) — keep for a later cycle.
|
|
846
|
+
if (!loadedValues.has(val)) {
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
// Consume one selectable option per occurrence; drop once exhausted.
|
|
850
|
+
const remaining = selectableByValue.get(val) || 0;
|
|
851
|
+
if (remaining > 0) {
|
|
852
|
+
selectableByValue.set(val, remaining - 1);
|
|
853
|
+
return true;
|
|
854
|
+
}
|
|
855
|
+
return false;
|
|
856
|
+
});
|
|
857
|
+
|
|
858
|
+
if (reconciled.length !== valueArray.length) {
|
|
859
|
+
// This is an internal correction, not a consumer's programmatic set,
|
|
860
|
+
// so preserve the selection-driven flag through the re-entrant
|
|
861
|
+
// updated() cycle it schedules. Otherwise that cycle would treat the
|
|
862
|
+
// reassignment as programmatic and drop `_selectedKey` mid-cascade,
|
|
863
|
+
// flipping resolution and looping.
|
|
864
|
+
this._valueChangeFromSelection = true;
|
|
668
865
|
this.value = serializeMultiSelectValue(reconciled);
|
|
669
866
|
valueReconciled = true;
|
|
670
867
|
}
|
|
@@ -676,7 +873,11 @@ class AuroMenu extends AuroElement {
|
|
|
676
873
|
// `hidden` is intentionally NOT excluded: the combobox toggles
|
|
677
874
|
// `hidden` as its type-ahead filter, so a filtered-out option is
|
|
678
875
|
// still a valid programmatic selection.
|
|
679
|
-
|
|
876
|
+
// Prefer the option the user actually selected (tracked by
|
|
877
|
+
// `_selectedKey`) so a click on the second of two options sharing a
|
|
878
|
+
// `value` resolves back to that exact element instead of the first
|
|
879
|
+
// value match. Falls back to first-by-value for programmatic sets.
|
|
880
|
+
const matchingOption = resolveSelectedOption(this.items, this.value, this._selectedKey);
|
|
680
881
|
|
|
681
882
|
if (matchingOption) {
|
|
682
883
|
newSelected = matchingOption;
|
|
@@ -904,6 +1105,14 @@ class AuroMenu extends AuroElement {
|
|
|
904
1105
|
}
|
|
905
1106
|
});
|
|
906
1107
|
|
|
1108
|
+
// Assign private keys once items are populated. Only the root menu assigns
|
|
1109
|
+
// keys: its `items` is a deep query that already includes nested submenu
|
|
1110
|
+
// options, so a single pass keys the entire tree. Nested menus skip this
|
|
1111
|
+
// and inherit keys from the root.
|
|
1112
|
+
if (this.rootMenu) {
|
|
1113
|
+
this._assignOptionKeys();
|
|
1114
|
+
}
|
|
1115
|
+
|
|
907
1116
|
if (this.noCheckmark) {
|
|
908
1117
|
this.updateItemsState(new Map([
|
|
909
1118
|
[
|
|
@@ -920,6 +1129,31 @@ class AuroMenu extends AuroElement {
|
|
|
920
1129
|
}));
|
|
921
1130
|
}
|
|
922
1131
|
|
|
1132
|
+
/**
|
|
1133
|
+
* Assigns a private, auto-generated unique key (`_optionKey`) to each menu
|
|
1134
|
+
* option that does not already have one. Keys are internal state on the
|
|
1135
|
+
* element instance — never reflected as an attribute or exposed publicly —
|
|
1136
|
+
* and let selection tracking distinguish options that share the same `value`.
|
|
1137
|
+
*
|
|
1138
|
+
* The `_optionKey === undefined` guard makes this idempotent: options keep the
|
|
1139
|
+
* key they were first assigned across re-renders and slot changes, and if a
|
|
1140
|
+
* nested menu's lifecycle runs a pass before the root, options simply wait for
|
|
1141
|
+
* the root to key them (or keep whatever key they already hold).
|
|
1142
|
+
* @private
|
|
1143
|
+
*/
|
|
1144
|
+
_assignOptionKeys() {
|
|
1145
|
+
if (!this.items) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
this.items.forEach((option) => {
|
|
1150
|
+
if (option._optionKey === undefined) {
|
|
1151
|
+
this._optionKeyCounter += 1;
|
|
1152
|
+
option._optionKey = `${this._menuInstanceId}-${this._optionKeyCounter}`;
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1156
|
+
|
|
923
1157
|
// Logic Methods
|
|
924
1158
|
|
|
925
1159
|
/**
|
|
@@ -929,24 +1163,28 @@ class AuroMenu extends AuroElement {
|
|
|
929
1163
|
*/
|
|
930
1164
|
handleSelectState(option) {
|
|
931
1165
|
if (this.multiSelect) {
|
|
932
|
-
const currentValue = this.formattedValue || [];
|
|
933
1166
|
const currentSelected = this.optionSelected || [];
|
|
934
1167
|
|
|
935
|
-
if (!currentValue.includes(option.value)) {
|
|
936
|
-
this.value = serializeMultiSelectValue([
|
|
937
|
-
...currentValue,
|
|
938
|
-
option.value
|
|
939
|
-
]);
|
|
940
|
-
}
|
|
941
1168
|
if (!currentSelected.includes(option)) {
|
|
942
1169
|
this.optionSelected = [
|
|
943
1170
|
...currentSelected,
|
|
944
1171
|
option
|
|
945
1172
|
];
|
|
946
1173
|
}
|
|
1174
|
+
|
|
1175
|
+
// Re-sort by DOM order and rebuild `_selectedKey`/`value` from the
|
|
1176
|
+
// selected set so display order stays consistent with the menu, not with
|
|
1177
|
+
// click order.
|
|
1178
|
+
this._sortSelectedByDomOrder();
|
|
947
1179
|
} else {
|
|
948
1180
|
this.value = option.value;
|
|
949
1181
|
this.optionSelected = option;
|
|
1182
|
+
// Track the specific option the user selected so the value→option
|
|
1183
|
+
// reconciliation in updated() resolves back to this exact element even
|
|
1184
|
+
// when another option shares the same `value`.
|
|
1185
|
+
this._selectedKey = option._optionKey;
|
|
1186
|
+
// Mark this `value` change as selection-driven so updated() trusts the key.
|
|
1187
|
+
this._valueChangeFromSelection = true;
|
|
950
1188
|
}
|
|
951
1189
|
|
|
952
1190
|
this._index = this.items.indexOf(option);
|
|
@@ -959,18 +1197,22 @@ class AuroMenu extends AuroElement {
|
|
|
959
1197
|
*/
|
|
960
1198
|
handleDeselectState(option) {
|
|
961
1199
|
if (this.multiSelect) {
|
|
962
|
-
// Remove this
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
this.optionSelected = this.optionSelected.filter((val) => val !== option);
|
|
1200
|
+
// Remove this exact element from the selection (identity, not value — two
|
|
1201
|
+
// options can share a `value`), then rebuild `value`/`_selectedKey` from
|
|
1202
|
+
// the remaining set in DOM order. An empty result collapses to undefined.
|
|
1203
|
+
this.optionSelected = this.optionSelected.filter((selected) => selected !== option);
|
|
967
1204
|
if (this.optionSelected.length === 0) {
|
|
968
1205
|
this.optionSelected = undefined;
|
|
1206
|
+
this._selectedKey = undefined;
|
|
1207
|
+
this.value = undefined;
|
|
1208
|
+
} else {
|
|
1209
|
+
this._sortSelectedByDomOrder();
|
|
969
1210
|
}
|
|
970
1211
|
} else {
|
|
971
1212
|
// For single-select: Back to undefined when deselected
|
|
972
1213
|
this.value = undefined;
|
|
973
1214
|
this.optionSelected = undefined;
|
|
1215
|
+
this._selectedKey = undefined;
|
|
974
1216
|
}
|
|
975
1217
|
|
|
976
1218
|
// Update the index tracking
|
|
@@ -994,9 +1236,46 @@ class AuroMenu extends AuroElement {
|
|
|
994
1236
|
clearSelection() {
|
|
995
1237
|
this.optionSelected = undefined;
|
|
996
1238
|
this.value = undefined;
|
|
1239
|
+
this._selectedKey = undefined;
|
|
997
1240
|
this._index = -1;
|
|
998
1241
|
}
|
|
999
1242
|
|
|
1243
|
+
/**
|
|
1244
|
+
* Re-sorts the multi-select selection into DOM order and rebuilds the derived
|
|
1245
|
+
* `_selectedKey` and `value` from `optionSelected`. Selection is always stored
|
|
1246
|
+
* and serialized in the order options appear in the menu, never in click
|
|
1247
|
+
* order — so selecting C then A yields `[A, C]`.
|
|
1248
|
+
* @private
|
|
1249
|
+
*/
|
|
1250
|
+
_sortSelectedByDomOrder() {
|
|
1251
|
+
if (!this.multiSelect || !Array.isArray(this.optionSelected) || !this.items) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const indexMap = new Map(this.items.map((item, index) => [
|
|
1256
|
+
item,
|
|
1257
|
+
index
|
|
1258
|
+
]));
|
|
1259
|
+
|
|
1260
|
+
// Sorting in place mutates `optionSelected` without a new array reference,
|
|
1261
|
+
// which Lit's `===` change-detection cannot see on its own — but that is
|
|
1262
|
+
// intentional and safe: both callers (handleSelectState / handleDeselectState)
|
|
1263
|
+
// assign a fresh `optionSelected` array immediately before calling, so Lit
|
|
1264
|
+
// already has a changed reference to react to, and the `value` write below
|
|
1265
|
+
// schedules the updated() cycle that re-derives `optionSelected` in DOM order
|
|
1266
|
+
// via resolveSelectedOptions. Do not "fix" this into a new-array assignment.
|
|
1267
|
+
//
|
|
1268
|
+
// Sort any element no longer in `items` (a stale selection left over from a
|
|
1269
|
+
// dynamic rebuild that the consumer has not cleared) to the END rather than
|
|
1270
|
+
// the front, so it never displaces a live option to the head of the
|
|
1271
|
+
// serialized order. Value reconciliation drops it on the next updated() cycle.
|
|
1272
|
+
this.optionSelected.sort((optionA, optionB) => (indexMap.get(optionA) ?? this.items.length) - (indexMap.get(optionB) ?? this.items.length));
|
|
1273
|
+
this._selectedKey = this.optionSelected.map((option) => option._optionKey);
|
|
1274
|
+
this.value = serializeMultiSelectValue(this.optionSelected.map((option) => option.value));
|
|
1275
|
+
// Mark this `value` change as selection-driven so updated() trusts the keys.
|
|
1276
|
+
this._valueChangeFromSelection = true;
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1000
1279
|
/**
|
|
1001
1280
|
* Resets the menu to its initial state.
|
|
1002
1281
|
* This is the only way to return value to undefined.
|
|
@@ -1006,6 +1285,7 @@ class AuroMenu extends AuroElement {
|
|
|
1006
1285
|
// Reset to undefined - initial state
|
|
1007
1286
|
this.value = undefined;
|
|
1008
1287
|
this.optionSelected = undefined;
|
|
1288
|
+
this._selectedKey = undefined;
|
|
1009
1289
|
this._index = -1;
|
|
1010
1290
|
|
|
1011
1291
|
// Clear active option state so a follow-up open/navigation starts fresh
|
|
@@ -1067,6 +1347,21 @@ class AuroMenu extends AuroElement {
|
|
|
1067
1347
|
this.initItems();
|
|
1068
1348
|
}
|
|
1069
1349
|
|
|
1350
|
+
// Recover `_index` from the highlighted option when it has been reset to -1.
|
|
1351
|
+
// The updated() reconciliation resets `_index = -1` whenever the value
|
|
1352
|
+
// collapses to undefined while `optionActive` still points at the highlighted
|
|
1353
|
+
// option — e.g. deselecting the last remaining option in multi-select, or a
|
|
1354
|
+
// programmatic clearSelection() in single-select while keyboard focus is on an
|
|
1355
|
+
// option. Without this, reading `items[-1]` returns undefined and the re-select
|
|
1356
|
+
// no-ops until the highlight is moved away and back. Mirrors auro-combobox's
|
|
1357
|
+
// reconcileMenuIndex.
|
|
1358
|
+
if (this._index < 0 && this.optionActive && this.items) {
|
|
1359
|
+
const activeIndex = this.items.indexOf(this.optionActive);
|
|
1360
|
+
if (activeIndex >= 0) {
|
|
1361
|
+
this._index = activeIndex;
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1070
1365
|
// Get currently selected menu option based on index
|
|
1071
1366
|
const option = this.items ? this.items[this._index] : undefined;
|
|
1072
1367
|
|
|
@@ -1227,7 +1227,7 @@ class AuroHelpText extends i$2 {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
-
var formkitVersion = '
|
|
1230
|
+
var formkitVersion = '202608111803';
|
|
1231
1231
|
|
|
1232
1232
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
1233
1233
|
// See LICENSE in the project root for license information.
|
|
@@ -1227,7 +1227,7 @@ class AuroHelpText extends i$2 {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
-
var formkitVersion = '
|
|
1230
|
+
var formkitVersion = '202608111803';
|
|
1231
1231
|
|
|
1232
1232
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
1233
1233
|
// See LICENSE in the project root for license information.
|
|
@@ -1227,7 +1227,7 @@ class AuroHelpText extends i$2 {
|
|
|
1227
1227
|
}
|
|
1228
1228
|
}
|
|
1229
1229
|
|
|
1230
|
-
var formkitVersion = '
|
|
1230
|
+
var formkitVersion = '202608111803';
|
|
1231
1231
|
|
|
1232
1232
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
1233
1233
|
// See LICENSE in the project root for license information.
|
|
@@ -1166,7 +1166,7 @@ class AuroHelpText extends LitElement {
|
|
|
1166
1166
|
}
|
|
1167
1167
|
}
|
|
1168
1168
|
|
|
1169
|
-
var formkitVersion = '
|
|
1169
|
+
var formkitVersion = '202608111803';
|
|
1170
1170
|
|
|
1171
1171
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
1172
1172
|
// See LICENSE in the project root for license information.
|
|
@@ -1166,7 +1166,7 @@ class AuroHelpText extends LitElement {
|
|
|
1166
1166
|
}
|
|
1167
1167
|
}
|
|
1168
1168
|
|
|
1169
|
-
var formkitVersion = '
|
|
1169
|
+
var formkitVersion = '202608111803';
|
|
1170
1170
|
|
|
1171
1171
|
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
1172
1172
|
// See LICENSE in the project root for license information.
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
<auro-anchorlink fluid href="#noValidate" class="level2 body-xs">No Validation</auro-anchorlink>
|
|
34
34
|
<auro-anchorlink fluid href="#placeholder" class="level2 body-xs">Placeholder</auro-anchorlink>
|
|
35
35
|
<auro-anchorlink fluid href="#loading" class="level2 body-xs">Loading</auro-anchorlink>
|
|
36
|
+
<auro-anchorlink fluid href="#nonUniqueValues" class="level2 body-xs">Non-Unique Option Values</auro-anchorlink>
|
|
36
37
|
</auro-nav>
|
|
37
38
|
</nav>
|
|
38
39
|
<div class="mainContent">
|
|
@@ -1297,6 +1298,77 @@
|
|
|
1297
1298
|
</auro-select></code></pre>
|
|
1298
1299
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
1299
1300
|
</auro-accordion>
|
|
1301
|
+
<auro-header level="3" id="nonUniqueValues">Non-Unique Option Values</auro-header>
|
|
1302
|
+
<p>Two or more <code>auro-menuoption</code> elements may share the same <code>value</code>. This is common when the <code>value</code> represents a coarser grouping than the option label — for example, several airports that all serve the same city. The component tracks the specific option a user selects, so the correct label is displayed even when the underlying <code>value</code> is duplicated.</p>
|
|
1303
|
+
<div class="exampleWrapper">
|
|
1304
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/duplicate-values.html) -->
|
|
1305
|
+
<!-- The below content is automatically added from ./../apiExamples/duplicate-values.html -->
|
|
1306
|
+
<auro-select>
|
|
1307
|
+
<span slot="ariaLabel.bib.close">Close Popup</span>
|
|
1308
|
+
<span slot="bib.fullscreen.headline">Choose an airport</span>
|
|
1309
|
+
<span slot="label">Departure airport</span>
|
|
1310
|
+
<auro-menu>
|
|
1311
|
+
<auro-menuoption value="seattle">Seattle–Tacoma International (SEA)</auro-menuoption>
|
|
1312
|
+
<auro-menuoption value="seattle">Seattle Paine Field (PAE)</auro-menuoption>
|
|
1313
|
+
<auro-menuoption value="portland">Portland International (PDX)</auro-menuoption>
|
|
1314
|
+
<auro-menuoption value="spokane">Spokane International (GEG)</auro-menuoption>
|
|
1315
|
+
</auro-menu>
|
|
1316
|
+
</auro-select>
|
|
1317
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
1318
|
+
</div>
|
|
1319
|
+
<auro-accordion alignRight>
|
|
1320
|
+
<span slot="trigger">See code</span>
|
|
1321
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/duplicate-values.html) -->
|
|
1322
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/duplicate-values.html -->
|
|
1323
|
+
<pre class="language-html"><code class="language-html"><auro-select>
|
|
1324
|
+
<span slot="ariaLabel.bib.close">Close Popup</span>
|
|
1325
|
+
<span slot="bib.fullscreen.headline">Choose an airport</span>
|
|
1326
|
+
<span slot="label">Departure airport</span>
|
|
1327
|
+
<auro-menu>
|
|
1328
|
+
<auro-menuoption value="seattle">Seattle&ndash;Tacoma International (SEA)</auro-menuoption>
|
|
1329
|
+
<auro-menuoption value="seattle">Seattle Paine Field (PAE)</auro-menuoption>
|
|
1330
|
+
<auro-menuoption value="portland">Portland International (PDX)</auro-menuoption>
|
|
1331
|
+
<auro-menuoption value="spokane">Spokane International (GEG)</auro-menuoption>
|
|
1332
|
+
</auro-menu>
|
|
1333
|
+
</auro-select></code></pre>
|
|
1334
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
1335
|
+
</auro-accordion>
|
|
1336
|
+
<p>In <code>multiselect</code> mode, options that share a <code>value</code> are tracked independently, so each can be selected and removed on its own. Selections are stored in DOM order regardless of the order in which they were chosen.</p>
|
|
1337
|
+
<div class="exampleWrapper">
|
|
1338
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/duplicate-values-multiselect.html) -->
|
|
1339
|
+
<!-- The below content is automatically added from ./../apiExamples/duplicate-values-multiselect.html -->
|
|
1340
|
+
<auro-select multiselect>
|
|
1341
|
+
<span slot="ariaLabel.bib.close">Close Popup</span>
|
|
1342
|
+
<span slot="bib.fullscreen.headline">Choose airports</span>
|
|
1343
|
+
<label slot="placeholder">Select one or more airports</label>
|
|
1344
|
+
<span slot="label">Airports served</span>
|
|
1345
|
+
<auro-menu>
|
|
1346
|
+
<auro-menuoption value="seattle">Seattle–Tacoma International (SEA)</auro-menuoption>
|
|
1347
|
+
<auro-menuoption value="seattle">Seattle Paine Field (PAE)</auro-menuoption>
|
|
1348
|
+
<auro-menuoption value="portland">Portland International (PDX)</auro-menuoption>
|
|
1349
|
+
<auro-menuoption value="spokane">Spokane International (GEG)</auro-menuoption>
|
|
1350
|
+
</auro-menu>
|
|
1351
|
+
</auro-select>
|
|
1352
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
1353
|
+
</div>
|
|
1354
|
+
<auro-accordion alignRight>
|
|
1355
|
+
<span slot="trigger">See code</span>
|
|
1356
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/duplicate-values-multiselect.html) -->
|
|
1357
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/duplicate-values-multiselect.html -->
|
|
1358
|
+
<pre class="language-html"><code class="language-html"><auro-select multiselect>
|
|
1359
|
+
<span slot="ariaLabel.bib.close">Close Popup</span>
|
|
1360
|
+
<span slot="bib.fullscreen.headline">Choose airports</span>
|
|
1361
|
+
<label slot="placeholder">Select one or more airports</label>
|
|
1362
|
+
<span slot="label">Airports served</span>
|
|
1363
|
+
<auro-menu>
|
|
1364
|
+
<auro-menuoption value="seattle">Seattle&ndash;Tacoma International (SEA)</auro-menuoption>
|
|
1365
|
+
<auro-menuoption value="seattle">Seattle Paine Field (PAE)</auro-menuoption>
|
|
1366
|
+
<auro-menuoption value="portland">Portland International (PDX)</auro-menuoption>
|
|
1367
|
+
<auro-menuoption value="spokane">Spokane International (GEG)</auro-menuoption>
|
|
1368
|
+
</auro-menu>
|
|
1369
|
+
</auro-select></code></pre>
|
|
1370
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
1371
|
+
</auro-accordion>
|
|
1300
1372
|
</section>
|
|
1301
1373
|
</div>
|
|
1302
1374
|
</div>
|