@@ -279,7 +279,7 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
279279
280280 const contentBox = getIntrinsicSize ( data . contentEl . value , data . isRtl . value )
281281 const scrollParents = getScrollParents ( data . contentEl . value )
282- const viewportMargin = 12
282+ const viewportMargin = props . stickToTarget ? 0 : 12 // TOOD: prop.viewportMargin
283283
284284 if ( ! scrollParents . length ) {
285285 scrollParents . push ( document . documentElement )
@@ -302,10 +302,18 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
302302 }
303303 return scrollBox
304304 } , undefined ! )
305- viewport . x += viewportMargin
306- viewport . y += viewportMargin
307- viewport . width -= viewportMargin * 2
308- viewport . height -= viewportMargin * 2
305+
306+ if ( props . stickToTarget ) {
307+ viewport . x += Math . min ( 0 , targetBox . x )
308+ viewport . y += Math . min ( 0 , targetBox . y )
309+ viewport . width = Math . max ( viewport . width , targetBox . x + targetBox . width )
310+ viewport . height = Math . max ( viewport . height , targetBox . y + targetBox . height )
311+ } else {
312+ viewport . x += viewportMargin
313+ viewport . y += viewportMargin
314+ viewport . width -= viewportMargin * 2
315+ viewport . height -= viewportMargin * 2
316+ }
309317
310318 let placement = {
311319 anchor : preferredAnchor . value ,
@@ -397,19 +405,19 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
397405
398406 // shift
399407 if ( overflows . x . before ) {
400- if ( ! props . stickToTarget ) x += overflows . x . before
408+ x += overflows . x . before
401409 contentBox . x += overflows . x . before
402410 }
403411 if ( overflows . x . after ) {
404- if ( ! props . stickToTarget ) x -= overflows . x . after
412+ x -= overflows . x . after
405413 contentBox . x -= overflows . x . after
406414 }
407415 if ( overflows . y . before ) {
408- if ( ! props . stickToTarget ) y += overflows . y . before
416+ y += overflows . y . before
409417 contentBox . y += overflows . y . before
410418 }
411419 if ( overflows . y . after ) {
412- if ( ! props . stickToTarget ) y -= overflows . y . after
420+ y -= overflows . y . after
413421 contentBox . y -= overflows . y . after
414422 }
415423
@@ -419,9 +427,9 @@ function connectedLocationStrategy (data: LocationStrategyData, props: StrategyP
419427 available . x = viewport . width - overflows . x . before - overflows . x . after
420428 available . y = viewport . height - overflows . y . before - overflows . y . after
421429
422- if ( ! props . stickToTarget ) x += overflows . x . before
430+ x += overflows . x . before
423431 contentBox . x += overflows . x . before
424- if ( ! props . stickToTarget ) y += overflows . y . before
432+ y += overflows . y . before
425433 contentBox . y += overflows . y . before
426434 }
427435
0 commit comments