From 6b6050d79e5862431d7a6fa83f3655443062236f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Thu, 3 Apr 2025 10:30:44 +0200 Subject: [PATCH] pl-fe: i hate my life MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- packages/pl-fe/src/components/account.tsx | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/pl-fe/src/components/account.tsx b/packages/pl-fe/src/components/account.tsx index b39d3baed..b1f666cc5 100644 --- a/packages/pl-fe/src/components/account.tsx +++ b/packages/pl-fe/src/components/account.tsx @@ -178,14 +178,28 @@ const Account = ({ const intl = useIntl(); useLayoutEffect(() => { - const style: React.CSSProperties = {}; - const actionWidth = actionRef.current?.clientWidth || 0; + const onResize = () => { + const style: React.CSSProperties = {}; + const actionWidth = actionRef.current?.clientWidth || 0; + + if (overflowRef.current) { + style.maxWidth = Math.max(0, overflowRef.current.clientWidth - (withAvatar ? avatarSize + 12 : 0) - (actionWidth ? actionWidth + 12 : 0)); + } + + setStyle(style); + }; + + onResize(); if (overflowRef.current) { - style.maxWidth = Math.max(0, overflowRef.current.clientWidth - (withAvatar ? avatarSize + 12 : 0) - (actionWidth ? actionWidth + 12 : 0)); - } + const targetElement = overflowRef.current; + const resizeObserver = new ResizeObserver(onResize); + resizeObserver.observe(targetElement); - setStyle(style); + return () => { + resizeObserver.unobserve(targetElement); + }; + } }, [overflowRef, actionRef]);