@swiftwc/ui 0.0.0-dev.53 → 0.0.0-dev.54
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.
|
@@ -634,13 +634,40 @@ export class PickerView extends FormAssociatedBase {
|
|
|
634
634
|
#reflectSelectionOnButtons() {
|
|
635
635
|
if (devFlags.debug)
|
|
636
636
|
console.debug(`${_a.name} #reflectSelectionOnButtons`);
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
el.
|
|
640
|
-
// also sync the spawn (sheet/navigation) if open
|
|
641
|
-
if (this.#spawn)
|
|
642
|
-
for (const el of this.#spawn.querySelectorAll('list-view button[value]:not([slot])'))
|
|
637
|
+
const syncButtons = (root) => {
|
|
638
|
+
// 1. Sync plain value buttons (existing behavior)
|
|
639
|
+
for (const el of root.querySelectorAll('button[value]:not([slot])'))
|
|
643
640
|
el.querySelector('label-view[data-role="check"]')?.style.setProperty('visibility', el.getAttribute('value') === this.#selection ? 'visible' : 'hidden');
|
|
641
|
+
// 2. Sync `details` (optgroups) — open/mark if any descendant option matches selection
|
|
642
|
+
for (const details of root.querySelectorAll('details[is="disclosure-group"]')) {
|
|
643
|
+
const hasSelectedDescendant = [...details.querySelectorAll('button[value]')].some((btn) => btn.getAttribute('value') === this.#selection);
|
|
644
|
+
// Show/hide the check on the summary's label-view
|
|
645
|
+
details.querySelector(':scope>summary label-view[data-role="check"]')?.style.setProperty('visibility', hasSelectedDescendant ? 'visible' : 'hidden');
|
|
646
|
+
}
|
|
647
|
+
// 3. Sync nav-link buttons (those without `value` that spawn sub-pages)
|
|
648
|
+
// These wrap <datalist> children — mark them if any descendant value matches
|
|
649
|
+
for (const btn of root.querySelectorAll('button[navigation-link]:not([value])')) {
|
|
650
|
+
// Find the matching datalist node by label
|
|
651
|
+
const btnLabel = btn.querySelector('label-view span')?.textContent?.trim();
|
|
652
|
+
const matchingDatalist = [...(this.#slots?.get('list')?.assignedElements() ?? [])]
|
|
653
|
+
.flatMap((el) => [...el.querySelectorAll('datalist'), ...(el.tagName === 'DATALIST' ? [el] : [])])
|
|
654
|
+
.find((dl) => dl.getAttribute('data-label') === btnLabel);
|
|
655
|
+
const hasSelectedDescendant = matchingDatalist ? [...matchingDatalist.querySelectorAll('option')].some((opt) => extractTagFromOption(opt) === this.#selection) : false;
|
|
656
|
+
btn.querySelector('label-view[data-role="check"]')?.style.setProperty('visibility', hasSelectedDescendant ? 'visible' : 'hidden');
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
// Run on the host element (inline/menu styles)
|
|
660
|
+
syncButtons(this);
|
|
661
|
+
// Also sync the spawn if open (sheet/navigation-link styles)
|
|
662
|
+
if (this.#spawn)
|
|
663
|
+
syncButtons(this.#spawn);
|
|
664
|
+
// // walk all rendered buttons (inline has buttons in list, menu has buttons in menu-view)
|
|
665
|
+
// for (const el of this.querySelectorAll<HTMLButtonElement>('button[value]:not([slot])'))
|
|
666
|
+
// el.querySelector<HTMLElement>('label-view[data-role="check"]')?.style.setProperty('visibility', el.getAttribute('value') === this.#selection ? 'visible' : 'hidden')
|
|
667
|
+
// // also sync the spawn (sheet/navigation) if open
|
|
668
|
+
// if (this.#spawn)
|
|
669
|
+
// for (const el of this.#spawn.querySelectorAll<HTMLButtonElement>('list-view button[value]:not([slot])'))
|
|
670
|
+
// el.querySelector<HTMLElement>('label-view[data-role="check"]')?.style.setProperty('visibility', el.getAttribute('value') === this.#selection ? 'visible' : 'hidden')
|
|
644
671
|
}
|
|
645
672
|
get #currentTag() {
|
|
646
673
|
return this.#slots
|