From 473513c2460d4329d7d2e0a0ea69bf1310a072d1 Mon Sep 17 00:00:00 2001 From: J-Michalek <71264422+J-Michalek@users.noreply.github.com> Date: Thu, 22 May 2025 17:04:17 +0200 Subject: [PATCH] feat(Popover): add `anchor` slot (#4119) Co-authored-by: Jakub Co-authored-by: Benjamin Canac --- .../popover/PopoverAnchorSlotExample.vue | 19 ++++++++++++++++++ docs/content/3.components/popover.md | 15 ++++++++++++++ playground/app/pages/components/popover.vue | 16 +++++++++++++++ src/runtime/components/Popover.vue | 5 +++++ test/components/Popover.spec.ts | 3 ++- .../__snapshots__/Popover-vue.spec.ts.snap | 20 +++++++++++++++++++ .../__snapshots__/Popover.spec.ts.snap | 20 +++++++++++++++++++ 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 docs/app/components/content/examples/popover/PopoverAnchorSlotExample.vue diff --git a/docs/app/components/content/examples/popover/PopoverAnchorSlotExample.vue b/docs/app/components/content/examples/popover/PopoverAnchorSlotExample.vue new file mode 100644 index 00000000..c9c69e59 --- /dev/null +++ b/docs/app/components/content/examples/popover/PopoverAnchorSlotExample.vue @@ -0,0 +1,19 @@ + + + diff --git a/docs/content/3.components/popover.md b/docs/content/3.components/popover.md index 5a92c57a..14c6388a 100644 --- a/docs/content/3.components/popover.md +++ b/docs/content/3.components/popover.md @@ -202,6 +202,21 @@ name: 'popover-command-palette-example' --- :: +### With anchor slot + +You can use the `#anchor` slot to position the Popover against a custom element. + +::warning +This slot only works when `mode` is `click`. +:: + +::component-example +--- +collapse: true +name: 'popover-anchor-slot-example' +--- +:: + ## API ### Props diff --git a/playground/app/pages/components/popover.vue b/playground/app/pages/components/popover.vue index d2620248..6351cd12 100644 --- a/playground/app/pages/components/popover.vue +++ b/playground/app/pages/components/popover.vue @@ -1,5 +1,6 @@ @@ -103,6 +104,10 @@ const Component = computed(() => props.mode === 'hover' ? HoverCard : Popover) + + + + diff --git a/test/components/Popover.spec.ts b/test/components/Popover.spec.ts index 941d466b..885f0c7b 100644 --- a/test/components/Popover.spec.ts +++ b/test/components/Popover.spec.ts @@ -13,7 +13,8 @@ describe('Popover', () => { ['with ui', { props: { ...props, ui: { content: 'shadow-xl' } } }], // Slots ['with default slot', { props, slots: { default: () => 'Default slot' } }], - ['with content slot', { props, slots: { content: () => 'Content slot' } }] + ['with content slot', { props, slots: { content: () => 'Content slot' } }], + ['with anchor slot', { props, slots: { anchor: () => 'Anchor slot' } }] ])('renders %s correctly', async (nameOrHtml: string, options: { props?: PopoverProps, slots?: Partial }) => { const html = await ComponentRender(nameOrHtml, options, Popover) expect(html).toMatchSnapshot() diff --git a/test/components/__snapshots__/Popover-vue.spec.ts.snap b/test/components/__snapshots__/Popover-vue.spec.ts.snap index 67effe86..9a993dab 100644 --- a/test/components/__snapshots__/Popover-vue.spec.ts.snap +++ b/test/components/__snapshots__/Popover-vue.spec.ts.snap @@ -1,7 +1,22 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`Popover > renders with anchor slot correctly 1`] = ` +" +Anchor slot + + + +
+ +
+ + +" +`; + exports[`Popover > renders with arrow correctly 1`] = ` " + @@ -15,6 +30,7 @@ exports[`Popover > renders with arrow correctly 1`] = ` exports[`Popover > renders with class correctly 1`] = ` " + @@ -28,6 +44,7 @@ exports[`Popover > renders with class correctly 1`] = ` exports[`Popover > renders with content slot correctly 1`] = ` " + @@ -43,6 +60,7 @@ exports[`Popover > renders with content slot correctly 1`] = ` exports[`Popover > renders with default slot correctly 1`] = ` "Default slot + @@ -56,6 +74,7 @@ exports[`Popover > renders with default slot correctly 1`] = ` exports[`Popover > renders with open correctly 1`] = ` " + @@ -69,6 +88,7 @@ exports[`Popover > renders with open correctly 1`] = ` exports[`Popover > renders with ui correctly 1`] = ` " + diff --git a/test/components/__snapshots__/Popover.spec.ts.snap b/test/components/__snapshots__/Popover.spec.ts.snap index ecbe9202..35f00e64 100644 --- a/test/components/__snapshots__/Popover.spec.ts.snap +++ b/test/components/__snapshots__/Popover.spec.ts.snap @@ -1,7 +1,22 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`Popover > renders with anchor slot correctly 1`] = ` +" +Anchor slot + + + +
+ +
+ + +" +`; + exports[`Popover > renders with arrow correctly 1`] = ` " + @@ -15,6 +30,7 @@ exports[`Popover > renders with arrow correctly 1`] = ` exports[`Popover > renders with class correctly 1`] = ` " + @@ -28,6 +44,7 @@ exports[`Popover > renders with class correctly 1`] = ` exports[`Popover > renders with content slot correctly 1`] = ` " + @@ -43,6 +60,7 @@ exports[`Popover > renders with content slot correctly 1`] = ` exports[`Popover > renders with default slot correctly 1`] = ` "Default slot + @@ -56,6 +74,7 @@ exports[`Popover > renders with default slot correctly 1`] = ` exports[`Popover > renders with open correctly 1`] = ` " + @@ -69,6 +88,7 @@ exports[`Popover > renders with open correctly 1`] = ` exports[`Popover > renders with ui correctly 1`] = ` " +