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.

fix(quill): render actions and a close button on anchored toasts (#83032)

Adam Leith9c47f0e4e9a1
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index d08df68a50e1..2068d468beb8 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6111,7 +6111,7 @@ snapshots:
scenes-app-experiments--experiment-with-multi-step-funnel-metric--dark:
hash: v1.k794b7964.6c73e20e6bcfbd467e8e9dea7f6cbcd9d05ba8f99b99879a366d5fc14ae1d296.6QHCgNYcXclmThjruFfmFpJsfM5oode4JC1elbpZ-rE
scenes-app-experiments--experiment-with-multi-step-funnel-metric--light:
- hash: v1.k794b7964.97d7402f9b51d0c2d446c61c0022bb257b60230ee9ef045fb98f9a6f6881021a.u-DOTSJ-2l7aMIVwI4CBomzduA0B_q6-6kfVwbLKl5M
+ hash: v1.k794b7964.0f81873b7b3e44139ef64b33d35aaa9c9857943789e7f88fe0dd8eb9d84b6125.0yFYuT8reEOckBG0v7K4CTlrcHgCWGlaDbiVhp7Euck
scenes-app-experiments--experiment-with-multiple-metrics--dark:
hash: v1.k794b7964.935a9474cbc0ab0c65ece0051d8ebc3a88c8f40de3bb8a7a7621dbe1766a4105.2TXN7Cqx8Qd7XzXBjoaslAsm-r4qbXmG0Vlch8j6ph0
scenes-app-experiments--experiment-with-multiple-metrics--light:
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index eb357c4cf1c6..65073b5bf8d6 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -1095,6 +1095,22 @@ toast.dismiss(id)
toast({ title: 'Item archived', action: { label: 'Undo', onClick: () => restore() } })
```
+`anchoredToast` positions a toast next to an element instead of stacking it in the corner. It takes the same
+options plus an anchor. An anchored toast with an action also gets a close button, so give it `timeout: 0`
+when the user needs time to decide:
+
+```tsx
+import { anchoredToast } from '@posthog/quill-primitives'
+
+anchoredToast({ description: 'Copied!', anchor: buttonRef.current })
+anchoredToast({
+ title: 'Event deleted',
+ anchor: buttonRef.current,
+ timeout: 0,
+ action: { label: 'Undo', onClick: () => restore() },
+})
+```
+
### Theme Toggle
```tsx
diff --git a/packages/quill/packages/primitives/src/toast.stories.tsx b/packages/quill/packages/primitives/src/toast.stories.tsx
index ac955f6d35de..dcadd946d7bb 100644
--- a/packages/quill/packages/primitives/src/toast.stories.tsx
+++ b/packages/quill/packages/primitives/src/toast.stories.tsx
@@ -252,6 +252,40 @@ export const Anchored: Story = {
},
} satisfies Story
+export const AnchoredWithAction: Story = {
+ render: () => {
+ const buttonRef = useRef<HTMLButtonElement>(null)
+ const [deleted, setDeleted] = useState(false)
+
+ return (
+ <div className="flex items-center justify-center gap-3 p-20">
+ <Button
+ ref={buttonRef}
+ onClick={() => {
+ setDeleted(true)
+ anchoredToast({
+ title: 'Event deleted',
+ description: 'The event has been removed.',
+ anchor: buttonRef.current,
+ timeout: 0,
+ action: {
+ label: 'Undo',
+ onClick: () => setDeleted(false),
+ },
+ })
+ }}
+ disabled={deleted}
+ >
+ Delete event
+ </Button>
+ <span className="text-xs text-muted-foreground">
+ {deleted ? 'Deleted (click Undo in toast)' : 'Not deleted'}
+ </span>
+ </div>
+ )
+ },
+} satisfies Story
+
export const Dismiss: Story = {
render: () => {
const toastIdRef = useRef<string | undefined>(undefined)
diff --git a/packages/quill/packages/primitives/src/toast.tsx b/packages/quill/packages/primitives/src/toast.tsx
index fc4d1ef070d0..5b630c9a16f9 100644
--- a/packages/quill/packages/primitives/src/toast.tsx
+++ b/packages/quill/packages/primitives/src/toast.tsx
@@ -216,7 +216,22 @@ function AnchoredToastViewport(): React.ReactElement {
<ToastCard
toastTitle={t.title}
toastDescription={t.description}
+ action={
+ t.data?.action
+ ? {
+ label: t.data.action.label,
+ onClick: () => {
+ manager.close(t.id)
+ t.data?.action?.onClick()
+ },
+ }
+ : undefined
+ }
+ onDismiss={t.data?.action ? () => manager.close(t.id) : undefined}
className={cn(
+ // the viewport is a zero-width fixed box, so without this the card
+ // collapses to its longest word
+ 'w-max max-w-[320px]',
'data-[starting-style]:opacity-0 data-[starting-style]:scale-95',
'data-[ending-style]:opacity-0 data-[ending-style]:scale-95',
'transition-[opacity,transform] duration-200 ease-out'