From 1f2ed5243053a5aae0089f40f3abd20206c49e70 Mon Sep 17 00:00:00 2001 From: Flupsi Date: Sun, 3 Aug 2025 14:28:19 +0200 Subject: [PATCH] fix(ui): auto-close ancestral popover on any single choice #2429 --- front/src/components/ui/Popover.vue | 11 +- .../components/ui/popover/PopoverCheckbox.vue | 1 + .../src/components/ui/popover/PopoverItem.vue | 130 ++++++++++-------- .../components/ui/popover/PopoverRadio.vue | 8 +- .../ui/popover/PopoverRadioItem.vue | 3 + .../components/ui/popover/PopoverSubmenu.vue | 4 +- front/src/injection-keys.ts | 1 + front/ui-docs/components/ui/popover.md | 37 ++++- 8 files changed, 130 insertions(+), 65 deletions(-) diff --git a/front/src/components/ui/Popover.vue b/front/src/components/ui/Popover.vue index bc1c93776..aa4c76bdc 100644 --- a/front/src/components/ui/Popover.vue +++ b/front/src/components/ui/Popover.vue @@ -100,11 +100,15 @@ onScopeDispose(() => { stack?.splice(stack.indexOf(isOpen), 1) }) +// Check if there's an ancestral context to inherit close function from +const ancestralContext = inject(POPOVER_CONTEXT_INJECTION_KEY, null) + // Provide context for child items const hoveredItem = ref(-2) provide(POPOVER_CONTEXT_INJECTION_KEY, { items: ref(0), - hoveredItem + hoveredItem, + close: ancestralContext?.close ?? (() => { isOpen.value = false }) }) // Closing @@ -154,10 +158,7 @@ watch(isOpen, (isOpen) => { v-bind="color(colorProps)()" style="display:flex; flex-direction:column;" > - + diff --git a/front/src/components/ui/popover/PopoverCheckbox.vue b/front/src/components/ui/popover/PopoverCheckbox.vue index d45c1891f..408a26699 100644 --- a/front/src/components/ui/popover/PopoverCheckbox.vue +++ b/front/src/components/ui/popover/PopoverCheckbox.vue @@ -7,6 +7,7 @@ const value = defineModel()