Skip to content

Commit

Permalink
Fix the NotificationToast isVisible issue and increase duration (#1357)
Browse files Browse the repository at this point in the history
* increase toast duration

* fix the isVisible prop issue

* add changeset

* Update changeset

Co-authored-by: Connor Bär <connor-baer@users.noreply.github.com>

* address review comment

Co-authored-by: Connor Bär <connor-baer@users.noreply.github.com>
  • Loading branch information
amelako and connor-baer authored Jan 12, 2022
1 parent 681d43e commit 5d24f0d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-sheep-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Increased the NotificationToast's default duration to 6 seconds to match the accessibility guidelines.
5 changes: 5 additions & 0 deletions .changeset/small-cars-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Updated the NotificationToast's prop types, now the `iconLabel` prop is optional and the `isVisible` prop is internal only.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('NotificationToast', () => {
() => {
expect(baseNotificationToast.onClose).toHaveBeenCalledTimes(1);
},
{ timeout: 3000 },
{ timeout: 6000 },
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type NotificationToastProps = HTMLAttributes<HTMLDivElement> &
/**
* A clear and concise description of the icon and the Toast's purpose. If the toast body is self-explanatory pass an empty string.
*/
iconLabel: string;
iconLabel?: string;
};

// TODO: update the design token colors to be info/confirm/alert/notify, then remove this mapping
Expand Down Expand Up @@ -147,7 +147,7 @@ export function NotificationToast({
body,
headline,
onClose,
iconLabel,
iconLabel = '',
isVisible,
tracking,
duration, // this is the auto-dismiss duration, not the animation duration. We shouldn't pass it to the wrapper along with ...props
Expand Down
6 changes: 4 additions & 2 deletions packages/circuit-ui/components/ToastContext/ToastContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { spacing } from '../..';

import { BaseToastProps, ToastComponent } from './types';

const DEFAULT_TOAST_DURATION = 6000;

type ToastState<TProps extends BaseToastProps> = TProps &
StackItem & { component: ToastComponent<TProps> };

Expand Down Expand Up @@ -120,8 +122,8 @@ export function ToastProvider<TProps extends BaseToastProps>({
return undefined;
}
const duration = toastToDismiss.duration
? Math.max(toastToDismiss.duration, 3000)
: 3000;
? Math.max(toastToDismiss.duration, DEFAULT_TOAST_DURATION)
: DEFAULT_TOAST_DURATION;
const timeoutId = setTimeout(() => {
context.removeToast(toastToDismiss);
}, duration);
Expand Down
4 changes: 2 additions & 2 deletions packages/circuit-ui/components/ToastContext/createUseToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export function createUseToast<T extends BaseToastProps>(
component: ToastComponent<T>,
) {
return (): {
setToast: (props: T) => void;
setToast: (props: Omit<T, 'isVisible'>) => void;
} => {
const context = useContext(ToastContext);

return useMemo(
() => ({
setToast: (props: T): void => {
setToast: (props: Omit<T, 'isVisible'>): void => {
const id = uniqueId('toast_');
context.setToast({ ...props, id, component });
},
Expand Down

1 comment on commit 5d24f0d

@vercel
Copy link

@vercel vercel bot commented on 5d24f0d Jan 12, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.