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 the NotificationToast isVisible issue and increase duration #1357

Merged
merged 6 commits into from
Jan 12, 2022
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
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;
amelako marked this conversation as resolved.
Show resolved Hide resolved
};

// 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
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
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