-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: feedback diglog position (#158)
- Loading branch information
1 parent
70221f5
commit 02e786b
Showing
7 changed files
with
63 additions
and
10 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
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
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
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,39 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { elementIds } from '../const'; | ||
|
||
const parentId = elementIds.widgetWindow; | ||
const childId = elementIds.uikitModal; | ||
|
||
function useDynamicAttachModal() { | ||
useEffect(() => { | ||
// Set up a MutationObserver to monitor changes in the parent element | ||
const observer = new MutationObserver((mutations) => { | ||
mutations.forEach((mutation) => { | ||
if (mutation.addedNodes.length) { | ||
// Check if the added nodes include the one with parentId | ||
Array.from(mutation.addedNodes).forEach((node) => { | ||
if (node?.id === parentId) { | ||
const parent = document.getElementById(parentId); | ||
const child = document.getElementById(childId); | ||
if (parent && child) { | ||
parent.appendChild(child); | ||
// Disconnect the observer once the child is attached | ||
observer.disconnect(); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
|
||
// Set the observer to monitor the entire document | ||
observer.observe(document.body, { childList: true, subtree: true }); | ||
|
||
return () => { | ||
observer?.disconnect(); | ||
}; | ||
}, []); | ||
} | ||
|
||
export default useDynamicAttachModal; |