Skip to content

Commit 5b0d6ef

Browse files
authored
ref(cmdk) fix panel container (#112236)
Fixes widgetBuilder panel container by anchoring its position to the main element
1 parent 4f3f61b commit 5b0d6ef

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

static/app/views/dashboards/widgetBuilder/components/newWidgetBuilder.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,30 @@ export function WidgetBuilderV2({
104104
}
105105
}, []);
106106

107+
const [mainContentPosition, setMainContentPosition] = useState<{
108+
left: number;
109+
top: number;
110+
} | null>(null);
111+
useEffect(() => {
112+
const mainContentElement = document.querySelector('main');
113+
114+
const observer = new ResizeObserver(entries => {
115+
for (const entry of entries) {
116+
if (entry.target === mainContentElement) {
117+
const rect = entry.target.getBoundingClientRect();
118+
setMainContentPosition({top: rect.top, left: rect.left});
119+
}
120+
}
121+
});
122+
if (mainContentElement) {
123+
observer.observe(mainContentElement);
124+
}
125+
126+
return () => {
127+
observer.disconnect();
128+
};
129+
}, []);
130+
107131
const dimensions = useDimensions({elementRef: navigationElementRef});
108132

109133
const handleDragEnd = ({over}: any) => {
@@ -168,12 +192,12 @@ export function WidgetBuilderV2({
168192
? isMediumScreen
169193
? {
170194
left: 0,
171-
top: `${dimensions.height ?? 0}px`,
195+
top: `${mainContentPosition?.top ?? 0}px`,
172196
willChange: 'top',
173197
}
174198
: {
175199
left: `${dimensions.width ?? 0}px`,
176-
top: 0,
200+
top: `${mainContentPosition?.top ?? 0}px`,
177201
willChange: 'left',
178202
}
179203
: undefined

0 commit comments

Comments
 (0)