diff options
author | crupest <crupest@outlook.com> | 2020-11-04 17:17:49 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-11-04 17:17:49 +0800 |
commit | 1f2299b2ac42ac0bd29668999136db11d10de449 (patch) | |
tree | a281e1ef039edf4137b60074effe44378ee61ae3 /FrontEnd/src/app/views/common/alert | |
parent | 40c32cd9c1e6c1aeae3b2911c7acf14e3031381d (diff) | |
download | timeline-1f2299b2ac42ac0bd29668999136db11d10de449.tar.gz timeline-1f2299b2ac42ac0bd29668999136db11d10de449.tar.bz2 timeline-1f2299b2ac42ac0bd29668999136db11d10de449.zip |
feat: Click on alert makes alert not auto dismiss.
Diffstat (limited to 'FrontEnd/src/app/views/common/alert')
-rw-r--r-- | FrontEnd/src/app/views/common/alert/AlertHost.tsx | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/FrontEnd/src/app/views/common/alert/AlertHost.tsx b/FrontEnd/src/app/views/common/alert/AlertHost.tsx index c74f18e2..f50e41ad 100644 --- a/FrontEnd/src/app/views/common/alert/AlertHost.tsx +++ b/FrontEnd/src/app/views/common/alert/AlertHost.tsx @@ -22,6 +22,8 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => { const { t } = useTranslation(); + const timerTag = React.useRef<number | null>(null); + React.useEffect(() => { const tag = dismissTime === "never" @@ -29,6 +31,7 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => { : typeof dismissTime === "number" ? window.setTimeout(props.close, dismissTime) : window.setTimeout(props.close, 5000); + timerTag.current = tag; return () => { if (tag != null) { window.clearTimeout(tag); @@ -40,6 +43,12 @@ export const AutoCloseAlert: React.FC<AutoCloseAlertProps> = (props) => { <Alert className="m-3" variant={alert.type ?? "primary"} + onClick={() => { + const { current: tag } = timerTag; + if (tag != null) { + window.clearTimeout(tag); + } + }} onClose={props.close} dismissible > |