Skip to content

Commit

Permalink
WRR-16145: ContextualPopupDecorator: Modified to update position when…
Browse files Browse the repository at this point in the history
… DOM tree changes

Enact-DCO-1.0-Signed-off-by: Hyelyn Kim (myelyn.kim@lge.com)
  • Loading branch information
mmyelyn committed Jan 6, 2025
1 parent a82077e commit 621a845
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ContextualPopupDecorator/ContextualPopupDecorator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global ResizeObserver */
/* global MutationObserver ResizeObserver */

/**
* A higher-order component to add a Sandstone styled popup to a component.
Expand Down Expand Up @@ -301,6 +301,12 @@ const Decorator = hoc(defaultConfig, (config, Wrapped) => {
this.positionContextualPopup();
});
}

if (typeof MutationObserver === 'function') {
this.mutationObserver = new MutationObserver(() => {
this.positionContextualPopup();
});
}
}

getSnapshotBeforeUpdate (prevProps, prevState) {
Expand Down Expand Up @@ -355,6 +361,11 @@ const Decorator = hoc(defaultConfig, (config, Wrapped) => {
this.resizeObserver.disconnect();
this.resizeObserver = null;
}

if (this.mutationObserver) {
this.mutationObserver.disconnect();
this.mutationObserver = null;
}
}

generateId = () => {
Expand Down Expand Up @@ -619,6 +630,14 @@ const Decorator = hoc(defaultConfig, (config, Wrapped) => {
this.resizeObserver.disconnect();
}
}

if (this.mutationObserver) {
if (node) {
this.mutationObserver.observe(document.body, {attributes: true, childList: true, subtree: true});
} else {
this.mutationObserver.disconnect();
}
}
};

handle = handle.bind(this);
Expand Down

0 comments on commit 621a845

Please sign in to comment.