-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Notification): fix attach render bug (#3306)
* fix(notification): attach传递root id 时,notification会覆盖整个react app render 出的dom节点 * chore: update snapshot --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7d321e9
commit f59fa5f
Showing
4 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
import { NotificationPlugin, Button, Space } from 'tdesign-react'; | ||
|
||
export default function NotificationExample() { | ||
const timerRef = useRef<any>(); | ||
const openInfoNotification = () => { | ||
NotificationPlugin.info({ | ||
title: '信息', | ||
content: '这是一条可以自动关闭的消息通知, 未配置attach', | ||
duration: 3000, | ||
}); | ||
}; | ||
|
||
const openSuccessNotification = () => { | ||
NotificationPlugin.success({ | ||
attach: '#app', | ||
title: '信息', | ||
content: '这是一条可以自动关闭的消息通知, 配置attach 为 #app', | ||
duration: 3000, | ||
}); | ||
}; | ||
|
||
const openWarningNotification = () => { | ||
NotificationPlugin.warning({ | ||
attach: '#app', | ||
title: '信息', | ||
content: '这是一条可以自动关闭的消息通知, 配置attach 为 #app', | ||
duration: 3000, | ||
}); | ||
}; | ||
|
||
const openErrorNotification = () => { | ||
NotificationPlugin.error({ | ||
attach: '#app', | ||
title: '信息', | ||
content: '这是一条可以自动关闭的消息通知, 配置attach 为 #app', | ||
duration: 3000, | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
if (timerRef.current) { | ||
clearTimeout(timerRef.current); | ||
} | ||
timerRef.current = setTimeout(() => { | ||
NotificationPlugin.error({ | ||
attach: '#app', | ||
title: '信息', | ||
content: '这是一条可以自动关闭的消息通知, useEffect定时2000ms触发', | ||
duration: 10000, | ||
}); | ||
}, 2000); | ||
}, []); | ||
|
||
return ( | ||
<Space> | ||
<Button onClick={() => openInfoNotification()}>信息</Button> | ||
<Button onClick={() => openSuccessNotification()}>成功</Button> | ||
<Button onClick={() => openWarningNotification()}>警告</Button> | ||
<Button onClick={() => openErrorNotification()}>错误</Button> | ||
</Space> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters