From f3302d6843452248a60370e82f7c22ccd07ad6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oddbj=C3=B8rn=20=C3=98vernes?= Date: Fri, 26 Jan 2024 14:04:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Snackbar:=20check=20if=20"open"?= =?UTF-8?q?=20before=20autohide=20timer=20(#3241)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Snackbar/Snackbar.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx b/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx index 624cf24ed3..c935489e15 100644 --- a/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx +++ b/packages/eds-core-react/src/components/Snackbar/Snackbar.tsx @@ -98,15 +98,14 @@ export const Snackbar = forwardRef( useEffect(() => { setVisible(open) - - timer.current = setTimeout(() => { - setVisible(false) - - if (onClose) { - onClose() - } - }, autoHideDuration) - + if (open) { + timer.current = setTimeout(() => { + setVisible(false) + if (onClose) { + onClose() + } + }, autoHideDuration) + } return () => clearTimeout(timer.current) }, [open, autoHideDuration, setVisible, onClose])