@@ -258,8 +258,11 @@ export class HoverWidget extends Widget {
258
258
}
259
259
} ;
260
260
261
+ // These calls adjust the position depending on spacing.
261
262
this . adjustHorizontalHoverPosition ( targetRect ) ;
262
263
this . adjustVerticalHoverPosition ( targetRect ) ;
264
+ // This call limits the maximum height of the hover.
265
+ this . adjustHoverMaxHeight ( targetRect ) ;
263
266
264
267
// Offset the hover position if there is a pointer so it aligns with the target element
265
268
this . _hoverContainer . style . padding = '' ;
@@ -410,19 +413,9 @@ export class HoverWidget extends Widget {
410
413
}
411
414
412
415
private adjustVerticalHoverPosition ( target : TargetRect ) : void {
413
- // Do not adjust vertical hover position if y cordiante is provided
414
- if ( this . _target . y !== undefined ) {
415
- return ;
416
- }
417
-
418
- // When force position is enabled, restrict max height
419
- if ( this . _forcePosition ) {
420
- const padding = ( this . _hoverPointer ? Constants . PointerSize : 0 ) + Constants . HoverBorderWidth ;
421
- if ( this . _hoverPosition === HoverPosition . ABOVE ) {
422
- this . _hover . containerDomNode . style . maxHeight = `${ target . top - padding } px` ;
423
- } else if ( this . _hoverPosition === HoverPosition . BELOW ) {
424
- this . _hover . containerDomNode . style . maxHeight = `${ window . innerHeight - target . bottom - padding } px` ;
425
- }
416
+ // Do not adjust vertical hover position if the y coordinate is provided
417
+ // or the position is forced
418
+ if ( this . _target . y !== undefined || this . _forcePosition ) {
426
419
return ;
427
420
}
428
421
@@ -443,6 +436,25 @@ export class HoverWidget extends Widget {
443
436
}
444
437
}
445
438
439
+ private adjustHoverMaxHeight ( target : TargetRect ) : void {
440
+ let maxHeight = window . innerHeight / 2 ;
441
+
442
+ // When force position is enabled, restrict max height
443
+ if ( this . _forcePosition ) {
444
+ const padding = ( this . _hoverPointer ? Constants . PointerSize : 0 ) + Constants . HoverBorderWidth ;
445
+ if ( this . _hoverPosition === HoverPosition . ABOVE ) {
446
+ maxHeight = Math . min ( maxHeight , target . top - padding ) ;
447
+ } else if ( this . _hoverPosition === HoverPosition . BELOW ) {
448
+ maxHeight = Math . min ( maxHeight , window . innerHeight - target . bottom - padding ) ;
449
+ }
450
+ }
451
+
452
+ // Make sure not to accidentally enlarge the hover when setting a maxHeight for it
453
+ maxHeight = Math . min ( maxHeight , this . _hover . containerDomNode . clientHeight ) ;
454
+
455
+ this . _hover . containerDomNode . style . maxHeight = `${ maxHeight } px` ;
456
+ }
457
+
446
458
private setHoverPointerPosition ( target : TargetRect ) : void {
447
459
if ( ! this . _hoverPointer ) {
448
460
return ;
0 commit comments