Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ToastNotification): fix typo in prop name #2122

Merged
merged 3 commits into from
Jan 3, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const NotDismissable: Story = {
export const AutoDismiss: Story = {
args: {
...Default.args,
dissmissType: 'auto',
dismissType: 'auto',
timeout: 500,
onDismiss: () => console.log('trigger onDismiss'),
},
Expand Down Expand Up @@ -111,7 +111,7 @@ const ToastNotificationManager = (args: Args) => {
>
<ToastNotification
{...args}
dissmissType="auto"
dismissType="auto"
onDismiss={() => {
setToasts(
toasts.map((thisToast) => {
Expand Down
14 changes: 13 additions & 1 deletion src/components/ToastNotification/ToastNotification.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@ describe('<ToastNotification />', () => {
it('generates an error when onDissmiss and type=auto are misused', async () => {
// One must use onDismiss if auto is used
render(
<ToastNotification dissmissType="auto" timeout={50} title="test" />,
<ToastNotification dismissType="auto" timeout={50} title="test" />,
);

await waitFor(() => expect(consoleErrorMock).toHaveBeenCalledTimes(1));
});

it('[EDS-1453] generates an error message when using the dissmissType prop', async () => {
render(<ToastNotification dissmissType="manual" title="test" />);

await waitFor(() => expect(consoleErrorMock).toHaveBeenCalledTimes(1));
});

it('[EDS-1453] generates no error when using the correct dismissType prop', async () => {
render(<ToastNotification dismissType="manual" title="test" />);

await waitFor(() => expect(consoleErrorMock).toHaveBeenCalledTimes(0));
});
});
});
27 changes: 22 additions & 5 deletions src/components/ToastNotification/ToastNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type ToastNotificationProps = {
*
* **Default is `"manual"`**.
*/
dissmissType?: 'manual' | 'auto';
dismissType?: 'manual' | 'auto';
/**
* Keyword to characterize the state of the notification
*/
Expand All @@ -40,6 +40,8 @@ export type ToastNotificationProps = {
* The title/heading of the notification
*/
title: string;
/** @deprecated Please use `dismissType` instead */
dissmissType?: 'manual' | 'auto'; // TODO(next-major): remove this misspelled prop at next major release
};

/**
Expand All @@ -49,7 +51,8 @@ export type ToastNotificationProps = {
*/
export const ToastNotification = ({
className,
dissmissType = 'manual',
dismissType = 'manual',
dissmissType,
onDismiss,
status = 'favorable',
timeout = 8000,
Expand All @@ -62,22 +65,36 @@ export const ToastNotification = ({
className,
);

// if both are defined, temporarily prefer the original value of dissmissType to avoid accidental overrides
const tempDismissType = dissmissType ?? dismissType;

assertEdsUsage(
[!!timeout && typeof onDismiss === 'undefined' && dissmissType === 'auto'],
[
!!timeout &&
typeof onDismiss === 'undefined' &&
tempDismissType === 'auto',
],
'When using dismissType=auto, an onDismiss method must be defined',
'error',
);

// TODO(next-major): remove this misspelled prop at next major release
assertEdsUsage(
booc0mtaco marked this conversation as resolved.
Show resolved Hide resolved
[typeof dissmissType !== 'undefined'],
'`dissmissType` should not be used. Use `dismissType` instead',
'error',
);

useEffect(() => {
const expireId =
dissmissType === 'auto'
tempDismissType === 'auto'
? setTimeout(() => {
onDismiss && onDismiss();
}, timeout)
: undefined;

return () => clearTimeout(expireId);
}, [onDismiss, dissmissType, timeout]);
}, [onDismiss, tempDismissType, timeout]);

return (
<div className={componentClassName} {...other}>
Expand Down
Loading