From fc6ebe280c055f30cf82be2106bbc203c0832fe0 Mon Sep 17 00:00:00 2001 From: Ricardo Sawir Date: Fri, 12 Jun 2026 16:00:07 +0700 Subject: [PATCH] feat: add data-toast-id attribute to toast element (#714) Expose the toast ID as a data-toast-id attribute on the rendered
  • element. This enables targeted testing in Playwright/Cypress/RTL, easier DOM querying for automation, and allows child elements inside the toast to retrieve the parent toast ID for dynamic dismissal. Closes #714 --- src/index.tsx | 1 + test/src/app/page.tsx | 7 +++++++ test/tests/basic.spec.ts | 10 ++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index ce031e8..58d5a9d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -272,6 +272,7 @@ const Toast = (props: ToastProps) => { toast?.classNames?.[toastType], )} data-sonner-toast="" + data-toast-id={String(toast.id)} data-rich-colors={toast.richColors ?? defaultRichColors} data-styled={!Boolean(toast.jsx || toast.unstyled || unstyled)} data-mounted={mounted} diff --git a/test/src/app/page.tsx b/test/src/app/page.tsx index ef50965..583602c 100644 --- a/test/src/app/page.tsx +++ b/test/src/app/page.tsx @@ -343,6 +343,13 @@ export default function Home({ searchParams }: any) { +