Skip to content

Commit

Permalink
fix: rendering of ReactNode descriptions (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
peetzweg committed Apr 10, 2024
1 parent a869bd5 commit 6c51bc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,12 @@ const Toast = (props: ToastProps) => {
classNames?.description,
toast?.classNames?.description,
)}
dangerouslySetInnerHTML={sanitizeHTML(toast.description as string)}
></div>
dangerouslySetInnerHTML={
typeof toast.description === 'string' ? sanitizeHTML(toast.description as string) : undefined
}
>
{typeof toast.description === 'object' ? toast.description : null}
</div>
) : null}
</div>
{React.isValidElement(toast.cancel) ? (
Expand Down
14 changes: 14 additions & 0 deletions test/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ export default function Home({ searchParams }: any) {
>
Updated Toast
</button>
<button
data-testid="string-description"
className="button"
onClick={() => toast('Custom Description', { description: 'string description' })}
>
String Description
</button>
<button
data-testid="react-node-description"
className="button"
onClick={() => toast('Custom Description', { description: <div>This is my custom ReactNode description</div> })}
>
ReactNode Description
</button>
{showAutoClose ? <div data-testid="auto-close-el" /> : null}
{showDismiss ? <div data-testid="dismiss-el" /> : null}
<Toaster
Expand Down
10 changes: 10 additions & 0 deletions test/tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,14 @@ test.describe('Basic functionality', () => {

await expect(button).toHaveCSS('background-color', 'rgb(219, 239, 255)');
});

test('string description is rendered', async ({ page }) => {
await page.getByTestId('string-description').click();
await expect(page.getByText('string description')).toHaveCount(1);
});

test('ReactNode description is rendered', async ({ page }) => {
await page.getByTestId('react-node-description').click();
await expect(page.getByText('This is my custom ReactNode description')).toHaveCount(1);
});
});

0 comments on commit 6c51bc8

Please sign in to comment.