Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/react/src/toast/description/ToastDescription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,34 @@ describe('<Toast.Description />', () => {
expect(titleElement).not.to.equal(null);
expect(titleElement.textContent).to.equal('description');
});

it('renders the description when passed to render prop', async () => {
function CustomList() {
Comment on lines +94 to +95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Title component has the same issue

return Toast.useToastManager().toasts.map((toastItem) => (
<Toast.Root key={toastItem.id} toast={toastItem} data-testid="root">
<Toast.Title data-testid="title" />
<Toast.Description
data-testid="description"
render={(props) => <div {...props}>Custom: {props.children}</div>}
/>
</Toast.Root>
));
}

const { user } = await render(
<Toast.Provider>
<Toast.Viewport>
<CustomList />
</Toast.Viewport>
<Button />
</Toast.Provider>,
);

const button = screen.getByRole('button', { name: 'add' });
await user.click(button);

const descriptionElement = screen.getByTestId('description');
expect(descriptionElement).not.to.equal(null);
expect(descriptionElement.textContent).to.equal('Custom: description');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ToastDescription = React.forwardRef(function ToastDescription(

const children = childrenProp ?? toast.description;

const shouldRender = Boolean(children);
const shouldRender = Boolean(children) || render !== undefined;

const id = useId(idProp);

Expand Down
30 changes: 30 additions & 0 deletions packages/react/src/toast/title/ToastTitle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,34 @@ describe('<Toast.Title />', () => {
expect(titleElement).not.to.equal(null);
expect(titleElement.textContent).to.equal('title');
});

it('renders the title when passed to render prop', async () => {
function CustomList() {
return Toast.useToastManager().toasts.map((toastItem) => (
<Toast.Root key={toastItem.id} toast={toastItem} data-testid="root">
<Toast.Title
data-testid="title"
render={(props) => <div {...props}>Custom: {props.children}</div>}
/>
<Toast.Description data-testid="description" />
</Toast.Root>
));
}

const { user } = await render(
<Toast.Provider>
<Toast.Viewport>
<CustomList />
</Toast.Viewport>
<Button />
</Toast.Provider>,
);

const button = screen.getByRole('button', { name: 'add' });
await user.click(button);

const titleElement = screen.getByTestId('title');
expect(titleElement).not.to.equal(null);
expect(titleElement.textContent).to.equal('Custom: title');
});
});
2 changes: 1 addition & 1 deletion packages/react/src/toast/title/ToastTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ToastTitle = React.forwardRef(function ToastTitle(

const children = childrenProp ?? toast.title;

const shouldRender = Boolean(children);
const shouldRender = Boolean(children) || render !== undefined;

const id = useId(idProp);

Expand Down
Loading