Skip to content

Commit d520ccd

Browse files
fix: Ensure runtime actions cause re-calculation of alert/flash wrapping (#3404)
1 parent 02afde8 commit d520ccd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/alert/actions-wrapper/index.tsx

+15-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,21 @@ export const ActionsWrapper = ({
6060
if (!ref.current || !containerWidth || !wrappedClass) {
6161
return;
6262
}
63-
const isRtl = getIsRtl(ref.current);
64-
const { offsetWidth, offsetLeft } = ref.current;
65-
const start = isRtl ? containerWidth - offsetWidth - offsetLeft : offsetLeft;
66-
// if the action slot is towards the left (right in RTL) of its container
67-
setWrapped(start < 100);
68-
}, [containerWidth, wrappedClass]);
63+
function check() {
64+
const isRtl = getIsRtl(ref.current);
65+
const { offsetWidth, offsetLeft } = ref.current!;
66+
const start = isRtl ? containerWidth! - offsetWidth - offsetLeft : offsetLeft;
67+
// if the action slot is towards the left (right in RTL) of its container
68+
setWrapped(start < 100);
69+
}
70+
71+
// Discovered actions are rendered by their plugin, so don't cause a
72+
// re-render of our React tree. So we observe for changes.
73+
const observer = new MutationObserver(check);
74+
observer.observe(ref.current, { attributes: false, childList: true, subtree: true });
75+
check();
76+
return () => observer.disconnect();
77+
});
6978
const actionButton = createActionButton(testUtilClasses, action, buttonText, onButtonClick);
7079
if (!actionButton && discoveredActions.length === 0) {
7180
return null;

0 commit comments

Comments
 (0)