Skip to content

Commit 2ad667d

Browse files
CompuIvesSaraVieira
authored andcommitted
Add condition for primary action in toast (codesandbox#1918)
Fixes codesandbox#1917
1 parent 653fb88 commit 2ad667d

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

packages/notifications/src/component/Toast.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,23 @@ export function Toast({ toast, removeToast, getRef }: Props) {
134134
fontSize: '.875rem',
135135
}}
136136
>
137-
<Button
138-
small
139-
onClick={() => {
140-
removeToast(toast.id);
141-
toast.notification.actions.primary[0].run();
142-
}}
143-
style={{
144-
marginTop: '1rem',
145-
marginRight: '0.75rem',
146-
lineHeight: 1,
147-
}}
148-
>
149-
{toast.notification.actions.primary[0].label}
150-
</Button>
137+
{toast.notification.actions.primary &&
138+
toast.notification.actions.primary[0] && (
139+
<Button
140+
small
141+
onClick={() => {
142+
removeToast(toast.id);
143+
toast.notification.actions.primary[0].run();
144+
}}
145+
style={{
146+
marginTop: '1rem',
147+
marginRight: '0.75rem',
148+
lineHeight: 1,
149+
}}
150+
>
151+
{toast.notification.actions.primary[0].label}
152+
</Button>
153+
)}
151154

152155
{toast.notification.actions.secondary &&
153156
toast.notification.actions.secondary[0] && (

packages/notifications/src/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface NotificationMessage {
2323
* Primary actions show up as buttons as part of the message and will close
2424
* the notification once clicked.
2525
*/
26-
primary: NotificationAction[];
26+
primary?: NotificationAction[];
2727
/**
2828
* Secondary actions are meant to provide additional configuration or context
2929
* for the notification and will show up less prominent. A notification does not

0 commit comments

Comments
 (0)