Skip to content

Commit 4443dc6

Browse files
committed
Fix resizing
1 parent b38ec7e commit 4443dc6

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/command-pallette/CommandPalletteUI/CommandPaletteSearchBar.tsx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export function CommandPaletteSearchBar({
3535
const showCompanion = useRecoilValue(showKymaCompanionState);
3636
const shouldShowDialog = shouldFocus ? shouldFocus : open;
3737

38+
const htmlWrapEl = document.getElementById('html-wrap');
39+
3840
const setShowDialog = (value: boolean) => {
3941
const modalPresent =
4042
document.querySelector('ui5-dialog[open]') ||
@@ -68,14 +70,34 @@ export function CommandPaletteSearchBar({
6870

6971
useEventListener('keydown', onKeyPress, [shouldShowDialog]);
7072

73+
let timer: ReturnType<typeof setTimeout>;
74+
function handleChangedWidth() {
75+
clearTimeout(timer);
76+
77+
timer = setTimeout(() => {
78+
setShellbarWidth(
79+
showCompanion.show
80+
? shellbarRef?.current?.getBoundingClientRect().width || 0
81+
: window.innerWidth,
82+
);
83+
}, 0);
84+
}
85+
7186
useEffect(() => {
72-
setShellbarWidth(
73-
showCompanion.show
74-
? shellbarRef?.current?.offsetWidth || 0
75-
: window.innerWidth,
76-
);
87+
const elementObserver = new ResizeObserver(() => {
88+
handleChangedWidth();
89+
});
90+
91+
if (htmlWrapEl) {
92+
// elementObserver.observe(shellbarRef.current);
93+
elementObserver.observe(htmlWrapEl);
94+
}
95+
return () => {
96+
console.log('disconnect');
97+
elementObserver.disconnect();
98+
};
7799
// eslint-disable-next-line react-hooks/exhaustive-deps
78-
}, [showCompanion, window.innerWidth, shellbarRef?.current?.offsetWidth]);
100+
}, [showCompanion]);
79101

80102
useEffect(() => {
81103
const shellbarCurr = shellbarRef?.current;
@@ -103,8 +125,6 @@ export function CommandPaletteSearchBar({
103125
}
104126
}, [shellbarRef?.current, shellbarWidth, shouldShowDialog]); // eslint-disable-line react-hooks/exhaustive-deps
105127

106-
const htmlWrapEl = document.getElementById('html-wrap');
107-
108128
return (
109129
<>
110130
<Input

src/command-pallette/CommandPalletteUI/CommandPaletteUI.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export function CommandPaletteUI({
238238
},
239239
[isHistoryMode, activeResultIndex, query, results],
240240
);
241+
241242
return (
242243
<Background hide={hide}>
243244
<div

0 commit comments

Comments
 (0)