1
1
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js" ;
2
2
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js" ;
3
3
import { getClosedPopupParent } from "@ui5/webcomponents-base/dist/util/PopupUtils.js" ;
4
+ import clamp from "@ui5/webcomponents-base/dist/util/clamp.js" ;
4
5
import Popup from "./Popup.js" ;
5
6
import PopoverPlacementType from "./types/PopoverPlacementType.js" ;
6
7
import PopoverVerticalAlign from "./types/PopoverVerticalAlign.js" ;
@@ -396,15 +397,44 @@ class Popover extends Popup {
396
397
397
398
this . _oldPlacement = placement ;
398
399
400
+ const left = clamp (
401
+ this . _left ,
402
+ Popover . MIN_OFFSET ,
403
+ document . documentElement . clientWidth - popoverSize . width - Popover . MIN_OFFSET ,
404
+ ) ;
405
+
406
+ const top = clamp (
407
+ this . _top ,
408
+ Popover . MIN_OFFSET ,
409
+ document . documentElement . clientHeight - popoverSize . height - Popover . MIN_OFFSET ,
410
+ ) ;
411
+
412
+ let { arrowX, arrowY } = placement ;
413
+
399
414
const popoverOnLeftBorder = this . _left === 0 ;
415
+ const popoverOnRightBorder = this . _left + popoverSize . width >= document . documentElement . clientWidth ;
416
+ if ( popoverOnLeftBorder ) {
417
+ arrowX -= Popover . MIN_OFFSET ;
418
+ } else if ( popoverOnRightBorder ) {
419
+ arrowX += Popover . MIN_OFFSET ;
420
+ }
421
+ this . arrowTranslateX = arrowX ;
422
+
400
423
const popoverOnTopBorder = this . _top === 0 ;
424
+ const popoverOnBottomBorder = this . _top + popoverSize . height >= document . documentElement . clientHeight ;
425
+ if ( popoverOnTopBorder ) {
426
+ arrowY -= Popover . MIN_OFFSET ;
427
+ } else if ( popoverOnBottomBorder ) {
428
+ arrowY += Popover . MIN_OFFSET ;
429
+ }
430
+ this . arrowTranslateY = arrowY ;
401
431
402
432
this . actualPlacementType = placement . placementType ;
403
- this . arrowTranslateX = popoverOnLeftBorder ? placement . arrowX - Popover . MIN_OFFSET : placement . arrowX ;
404
- this . arrowTranslateY = popoverOnTopBorder ? placement . arrowY - Popover . MIN_OFFSET : placement . arrowY ;
405
433
406
- this . style . left = `${ popoverOnLeftBorder ? Popover . MIN_OFFSET : this . _left } px` ;
407
- this . style . top = `${ popoverOnTopBorder ? Popover . MIN_OFFSET : this . _top } px` ;
434
+ Object . assign ( this . style , {
435
+ top : `${ top } px` ,
436
+ left : `${ left } px` ,
437
+ } ) ;
408
438
super . show ( ) ;
409
439
410
440
if ( stretching && this . _width ) {
@@ -413,25 +443,17 @@ class Popover extends Popup {
413
443
}
414
444
415
445
getPopoverSize ( ) {
416
- let width ,
417
- height ;
418
- let rect = this . getBoundingClientRect ( ) ;
419
-
420
- if ( this . opened ) {
421
- width = rect . width ;
422
- height = rect . height ;
423
-
424
- return { width, height } ;
446
+ if ( ! this . opened ) {
447
+ Object . assign ( this . style , {
448
+ display : "block" ,
449
+ top : "-10000px" ,
450
+ left : "-10000px" ,
451
+ } ) ;
425
452
}
426
453
427
- this . style . display = "block" ;
428
- this . style . top = "-10000px" ;
429
- this . style . left = "-10000px" ;
430
-
431
- rect = this . getBoundingClientRect ( ) ;
432
-
433
- width = rect . width ;
434
- height = rect . height ;
454
+ const rect = this . getBoundingClientRect ( ) ,
455
+ width = rect . width ,
456
+ height = rect . height ;
435
457
436
458
return { width, height } ;
437
459
}
0 commit comments