@@ -81,7 +81,8 @@ export class MgtFlyout extends MgtBaseComponent {
8181 // reset style for next update
8282 flyout . style . width = null ;
8383 flyout . style . setProperty ( '--mgt-flyout-set-width' , null ) ;
84- flyout . style . height = null ;
84+ flyout . style . setProperty ( '--mgt-flyout-set-height' , null ) ;
85+ flyout . style . maxHeight = null ;
8586 flyout . style . top = null ;
8687 flyout . style . left = null ;
8788 flyout . style . bottom = null ;
@@ -299,29 +300,47 @@ export class MgtFlyout extends MgtBaseComponent {
299300 left = anchorRect . left ;
300301 }
301302
302- if ( flyoutRect . height + 2 * this . _edgePadding > windowRect . height ) {
303- if ( flyoutRect . height >= windowRect . height ) {
304- height = windowRect . height ;
305- top = 0 ;
306- } else {
307- top = ( windowRect . height - flyoutRect . height ) / 2 ;
308- }
309- } else if (
310- this . avoidHidingAnchor &&
311- anchorRect . top + anchorRect . height + flyoutRect . height + this . _edgePadding > windowRect . height &&
312- anchorRect . top - flyoutRect . height - this . _edgePadding > 0
313- ) {
314- if ( windowRect . height - anchorRect . top + flyoutRect . height < 0 ) {
315- bottom = windowRect . height - flyoutRect . height - this . _edgePadding ;
303+ const anchorRectBottomToWindowBottom = windowRect . height - ( anchorRect . top + anchorRect . height ) ;
304+ const anchorRectTopToWindowTop = anchorRect . top ;
305+
306+ if ( this . avoidHidingAnchor ) {
307+ if ( anchorRectBottomToWindowBottom <= flyoutRect . height ) {
308+ if ( anchorRectTopToWindowTop < flyoutRect . height ) {
309+ if ( anchorRectTopToWindowTop > anchorRectBottomToWindowBottom ) {
310+ // more room top than bottom - render above
311+ bottom = windowRect . height - anchorRect . top ;
312+ height = anchorRectTopToWindowTop ;
313+ } else {
314+ // more room bottom than top
315+ top = anchorRect . bottom ;
316+ height = anchorRectBottomToWindowBottom ;
317+ }
318+ } else {
319+ // render above anchor
320+ bottom = windowRect . height - anchorRect . top ;
321+ height = anchorRectTopToWindowTop ;
322+ }
316323 } else {
317- bottom = Math . max ( windowRect . height - anchorRect . top , this . _edgePadding ) ;
324+ top = anchorRect . bottom ;
325+ height = anchorRectBottomToWindowBottom ;
318326 }
319327 } else {
320- if ( anchorRect . top + anchorRect . height + flyoutRect . height + this . _edgePadding > windowRect . height ) {
321- // it will render offscreen bellow, move it up a bit
322- top = windowRect . height - flyoutRect . height - this . _edgePadding ;
328+ if ( flyoutRect . height + 2 * this . _edgePadding > windowRect . height ) {
329+ // flyout wants to be higher than the window hight, and we don't need to avoid hiding the anchor
330+ // make the flyout height the height of the window
331+ if ( flyoutRect . height >= windowRect . height ) {
332+ height = windowRect . height ;
333+ top = 0 ;
334+ } else {
335+ top = ( windowRect . height - flyoutRect . height ) / 2 ;
336+ }
323337 } else {
324- top = Math . max ( anchorRect . top + anchorRect . height , this . _edgePadding ) ;
338+ if ( anchorRect . top + anchorRect . height + flyoutRect . height + this . _edgePadding > windowRect . height ) {
339+ // it will render offscreen bellow, move it up a bit
340+ top = windowRect . height - flyoutRect . height - this . _edgePadding ;
341+ } else {
342+ top = Math . max ( anchorRect . top + anchorRect . height , this . _edgePadding ) ;
343+ }
325344 }
326345 }
327346
@@ -342,14 +361,20 @@ export class MgtFlyout extends MgtBaseComponent {
342361 flyout . style . top = `${ top + windowRect . top } px` ;
343362 }
344363
345- flyout . style . height = height ? `${ height } px` : null ;
346-
347364 if ( width ) {
348365 // if we had to set the width, recalculate since the height could have changed
349366 flyout . style . width = `${ width } px` ;
350367 flyout . style . setProperty ( '--mgt-flyout-set-width' , `${ width } px` ) ;
351368 window . requestAnimationFrame ( ( ) => this . updateFlyout ( ) ) ;
352369 }
370+
371+ if ( height ) {
372+ flyout . style . maxHeight = `${ height } px` ;
373+ flyout . style . setProperty ( '--mgt-flyout-set-height' , `${ height } px` ) ;
374+ } else {
375+ flyout . style . maxHeight = null ;
376+ flyout . style . setProperty ( '--mgt-flyout-set-height' , `unset` ) ;
377+ }
353378 }
354379 }
355380
0 commit comments