@@ -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
0 commit comments