Skip to content

Commit

Permalink
move container back to original dom position when closed
Browse files Browse the repository at this point in the history
  • Loading branch information
JesmoDev committed Nov 2, 2023
1 parent fabcbb5 commit 7adc83a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/uui-popover-container/lib/uui-popover-polyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,27 @@ export function polyfill() {
window.addEventListener('click', this.polyfill_onClick);
window.addEventListener('focusout', this.polyfill_onFocusout);

//Find the dom position that the popover is currently at and save it so we can restore it later.
this.polyfill_originalParent = this.parentNode;
this.polyfill_originalNextSibling = this.nextSibling;

if (this.parentNode !== document.body) {
this.parentNode?.removeChild(this);
this.polyfill_hasBeenMovedToBody = true;
document.body.appendChild(this);
}
};
this.hidePopover = () => {
//Restore previous dom position.
if (this.polyfill_hasBeenMovedToBody) {
document.body.removeChild(this);
this.polyfill_hasBeenMovedToBody = false;
this.polyfill_originalParent?.insertBefore(
this,
this.polyfill_originalNextSibling
);
}

window.removeEventListener('click', this.polyfill_onClick);
window.removeEventListener('focusout', this.polyfill_onFocusout);
this.polyfill_parentPopoverContainer?.removeEventListener(
Expand Down

0 comments on commit 7adc83a

Please sign in to comment.