Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): add an arrow to popover (#83045)

Adam Leith82eec79bc115
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index e07c4ff4f8b8..eb357c4cf1c6 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -599,6 +599,22 @@ Icon-only trigger — only the chevron toggles, so the label can be its own butt
</Popover>
```
+Pass `arrow` for a pointer connecting the popover to its trigger — use it when the popover is anchored to a small or ambiguous target, and leave it off for panels that read as attached already. `PopoverContent` widens its default `sideOffset` to 9 to make room for it, and `PopoverArrow` is exported for popovers that place the arrow themselves.
+
+```tsx
+<PopoverContent side="top" arrow>
+ {/* content */}
+</PopoverContent>
+```
+
+The arrow inherits the popup's border and background, so restyling the popover carries it along — no arrow-specific overrides:
+
+```tsx
+<PopoverContent arrow className="border-2 border-primary">
+ {/* the arrow is 2px and accent-colored too */}
+</PopoverContent>
+```
+
`PopoverContent` forwards `collisionAvoidance` to the positioner. Pass `fallbackAxisSide: 'none'` to keep a tall panel on its requested axis (e.g. below the trigger, flipping above only if it won't fit) instead of jumping beside the trigger when vertical space is tight: `collisionAvoidance={{ side: 'flip', align: 'shift', fallbackAxisSide: 'none' }}`.
### Tooltip
diff --git a/packages/quill/packages/primitives/src/index.ts b/packages/quill/packages/primitives/src/index.ts
index a463107bda11..e52ed6d25627 100644
--- a/packages/quill/packages/primitives/src/index.ts
+++ b/packages/quill/packages/primitives/src/index.ts
@@ -270,7 +270,7 @@ export {
getPaginationRange,
type PaginationRangeItem,
} from './pagination'
-export { Popover, PopoverContent, PopoverTrigger } from './popover'
+export { Popover, PopoverArrow, PopoverContent, PopoverTrigger } from './popover'
export {
Progress,
ProgressIndicator,
diff --git a/packages/quill/packages/primitives/src/popover.css b/packages/quill/packages/primitives/src/popover.css
index b89a666c148d..02e6b0b333e1 100644
--- a/packages/quill/packages/primitives/src/popover.css
+++ b/packages/quill/packages/primitives/src/popover.css
@@ -22,6 +22,77 @@
transform: scale(0.97);
}
+ /*
+ * A square rotated onto its corner and half-buried in the popup: the buried half
+ * hides the border segment it stands on, the two exposed edges continue it, and
+ * the other two are dropped. `inherit` is what makes the arrow follow whatever
+ * border and background the popup ends up with, including a consumer's own.
+ */
+ .quill-popover__arrow {
+ width: 0.625rem;
+ height: 0.625rem;
+ background: inherit;
+ border: inherit;
+ rotate: 45deg;
+ }
+
+ /*
+ * Which corner points out is physical, because the rotation is. The logical sides
+ * take their left-to-right meaning here and get remapped under `[dir='rtl']` below
+ * — `:dir()` would read better, but it compiles down to a list of RTL languages,
+ * which misses a page that sets the direction without a matching `lang`.
+ */
+ .quill-popover__arrow[data-side='bottom'] {
+ top: -0.3125rem;
+ border-right: none;
+ border-bottom: none;
+ border-top-left-radius: 2px;
+ }
+
+ .quill-popover__arrow[data-side='top'] {
+ bottom: -0.3125rem;
+ border-top: none;
+ border-left: none;
+ border-bottom-right-radius: 2px;
+ }
+
+ .quill-popover__arrow[data-side='right'],
+ .quill-popover__arrow[data-side='inline-end'] {
+ left: -0.3125rem;
+ border-top: none;
+ border-right: none;
+ border-bottom-left-radius: 2px;
+ }
+
+ .quill-popover__arrow[data-side='left'],
+ .quill-popover__arrow[data-side='inline-start'] {
+ right: -0.3125rem;
+ border-bottom: none;
+ border-left: none;
+ border-top-right-radius: 2px;
+ }
+
+ /* clears the left-to-right mapping so the two rules below can apply the mirror of it */
+ [dir='rtl'] .quill-popover__arrow[data-side^='inline-'] {
+ inset-inline: auto;
+ border: inherit;
+ border-radius: 0;
+ }
+
+ [dir='rtl'] .quill-popover__arrow[data-side='inline-end'] {
+ right: -0.3125rem;
+ border-bottom: none;
+ border-left: none;
+ border-top-right-radius: 2px;
+ }
+
+ [dir='rtl'] .quill-popover__arrow[data-side='inline-start'] {
+ left: -0.3125rem;
+ border-top: none;
+ border-right: none;
+ border-bottom-left-radius: 2px;
+ }
+
.quill-popover__title {
font-size: var(--text-sm, 0.875rem);
font-weight: 500;
diff --git a/packages/quill/packages/primitives/src/popover.stories.tsx b/packages/quill/packages/primitives/src/popover.stories.tsx
index db884e93a9d1..87760fcaf675 100644
--- a/packages/quill/packages/primitives/src/popover.stories.tsx
+++ b/packages/quill/packages/primitives/src/popover.stories.tsx
@@ -2,7 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react'
import { useState } from 'react'
import { Button } from './button'
-import { Popover, PopoverContent, PopoverTrigger } from './popover'
+import { Popover, PopoverArrow, PopoverContent, PopoverTrigger } from './popover'
const meta = {
title: 'Primitives/Popover',
@@ -26,3 +26,47 @@ export const Default: Story = {
)
},
} satisfies Story
+
+export const WithArrow: Story = {
+ render: () => (
+ <div className="flex flex-col items-center gap-24 py-24">
+ {(['top', 'right', 'bottom', 'left'] as const).map((side) => (
+ <Popover key={side} open>
+ <PopoverTrigger render={<Button variant="outline">{side}</Button>} />
+ <PopoverContent side={side} arrow className="w-48">
+ <p>Points back at the trigger.</p>
+ </PopoverContent>
+ </Popover>
+ ))}
+ </div>
+ ),
+} satisfies Story
+
+// the arrow inherits the popup's border and background, so a restyled popover keeps its arrow
+export const WithCustomBorder: Story = {
+ render: () => (
+ <div className="flex items-center justify-center p-24">
+ <Popover open>
+ <PopoverTrigger render={<Button variant="outline">Open</Button>} />
+ <PopoverContent side="bottom" arrow className="w-56 rounded-lg border-2 border-primary">
+ <p>Artifacts placed here</p>
+ </PopoverContent>
+ </Popover>
+ </div>
+ ),
+} satisfies Story
+
+// PopoverArrow is exported for popovers that compose their own content order
+export const WithComposedArrow: Story = {
+ render: () => (
+ <div className="flex items-center justify-center p-24">
+ <Popover open>
+ <PopoverTrigger render={<Button variant="outline">Open</Button>} />
+ <PopoverContent side="bottom" sideOffset={8} className="w-48">
+ <PopoverArrow />
+ <p>Arrow placed by hand.</p>
+ </PopoverContent>
+ </Popover>
+ </div>
+ ),
+} satisfies Story
diff --git a/packages/quill/packages/primitives/src/popover.tsx b/packages/quill/packages/primitives/src/popover.tsx
index c1629b97ed04..d771449abb87 100644
--- a/packages/quill/packages/primitives/src/popover.tsx
+++ b/packages/quill/packages/primitives/src/popover.tsx
@@ -12,18 +12,34 @@ function PopoverTrigger({ ...props }: PopoverPrimitive.Trigger.Props): React.Rea
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
}
+function PopoverArrow({ className, ...props }: PopoverPrimitive.Arrow.Props): React.ReactElement {
+ return (
+ <PopoverPrimitive.Arrow data-slot="popover-arrow" className={cn('quill-popover__arrow', className)} {...props} />
+ )
+}
+
function PopoverContent({
className,
align = 'center',
alignOffset = 0,
side = 'bottom',
- sideOffset = 4,
+ arrow = false,
+ // the arrow tip juts ~7px past the popup, so it needs a wider gap than a flush popover to clear the trigger
+ sideOffset = arrow ? 9 : 4,
+ arrowPadding,
collisionAvoidance,
container,
+ children,
...props
}: PopoverPrimitive.Popup.Props &
- Pick<PopoverPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'collisionAvoidance'> &
- Pick<PopoverPrimitive.Portal.Props, 'container'>): React.ReactElement {
+ Pick<
+ PopoverPrimitive.Positioner.Props,
+ 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'arrowPadding' | 'collisionAvoidance'
+ > &
+ Pick<PopoverPrimitive.Portal.Props, 'container'> & {
+ /** Renders a pointer connecting the popover to its trigger. */
+ arrow?: boolean
+ }): React.ReactElement {
/*
* `container` opt-in lets consumers mount the popover inside a
* specific DOM subtree instead of `document.body`. Useful when
@@ -42,6 +58,7 @@ function PopoverContent({
alignOffset={alignOffset}
side={side}
sideOffset={sideOffset}
+ arrowPadding={arrowPadding}
collisionAvoidance={collisionAvoidance}
className="isolate"
>
@@ -52,7 +69,10 @@ function PopoverContent({
className
)}
{...props}
- />
+ >
+ {arrow && <PopoverArrow />}
+ {children}
+ </PopoverPrimitive.Popup>
</PopoverPrimitive.Positioner>
</PopoverPrimitive.Portal>
)
@@ -82,4 +102,4 @@ function PopoverDescription({ className, ...props }: PopoverPrimitive.Descriptio
)
}
-export { Popover, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger }
+export { Popover, PopoverArrow, PopoverContent, PopoverDescription, PopoverHeader, PopoverTitle, PopoverTrigger }