Skip to content

Commit 70f6f13

Browse files
authored
Refactor click outside handler to use event.composedPath for compatibility with Shadow Roots. Resolves #337 (#338)
1 parent ec4a34a commit 70f6f13

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

packages/streamdown/lib/mermaid/download-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ export const MermaidDownloadDropdown = ({
7979

8080
useEffect(() => {
8181
const handleClickOutside = (event: MouseEvent) => {
82+
const path = event.composedPath();
8283
if (
8384
dropdownRef.current &&
84-
!dropdownRef.current.contains(event.target as Node)
85+
!path.includes(dropdownRef.current)
8586
) {
8687
setIsOpen(false);
8788
}

packages/streamdown/lib/table/copy-dropdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export const TableCopyDropdown = ({
7373

7474
useEffect(() => {
7575
const handleClickOutside = (event: MouseEvent) => {
76+
const path = event.composedPath();
7677
if (
7778
dropdownRef.current &&
78-
!dropdownRef.current.contains(event.target as Node)
79+
!path.includes(dropdownRef.current)
7980
) {
8081
setIsOpen(false);
8182
}

packages/streamdown/lib/table/download-dropdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ export const TableDownloadDropdown = ({
145145

146146
useEffect(() => {
147147
const handleClickOutside = (event: MouseEvent) => {
148+
const path = event.composedPath();
148149
if (
149150
dropdownRef.current &&
150-
!dropdownRef.current.contains(event.target as Node)
151+
!path.includes(dropdownRef.current)
151152
) {
152153
setIsOpen(false);
153154
}

0 commit comments

Comments
 (0)