fix(popover): fix popover arrow direction

This commit is contained in:
songwanli2025@163.com 2020-01-02 14:19:27 +08:00
parent 90fb7ea091
commit e066e195e0
3 changed files with 8 additions and 9 deletions

View File

@ -253,7 +253,7 @@ export default {
this.active
? h('div', {
attrs: {
'n-placement': this.placement
'n-placement': this.adjustedPlacement
},
staticClass: 'n-popover-content',
class: {

View File

@ -144,7 +144,8 @@ export default {
return {
trackingElement: null,
trackedElement: null,
scrollListeners: []
scrollListeners: [],
adjustedPlacement: this.placement
}
},
mounted () {
@ -233,15 +234,13 @@ export default {
// console.log(contentBoundingClientRect)
// debugger
// console.log('scroll', activatorBoundingClientRect, contentBoundingClientRect)
const [placementTransform, suggestedTransformOrigin] = calcPlacementTransfrom(this.placement, activatorBoundingClientRect, contentBoundingClientRect, this.flip)
// console.log(this.trackingElement, this.positionMode, this.positionModeisAbsolute)
const [placementTransform, suggestedTransformOrigin, adjustedPlacement] = calcPlacementTransfrom(this.placement, activatorBoundingClientRect, contentBoundingClientRect, this.flip)
this.adjustedPlacement = adjustedPlacement
if (this.positionModeisAbsolute) {
const position = getPositionInAbsoluteMode(this.placement, suggestedTransformOrigin)
// console.log(suggestedTransformOrigin, position)
this.updatePositionInAbsoluteMode(position, suggestedTransformOrigin)
return
}
// console.log(placementTransform)
this.trackingElement.style.position = 'absolute'
this.trackingElement.style.top = placementTransform.top
this.trackingElement.style.left = placementTransform.left

View File

@ -37,13 +37,13 @@ function getAdjustedPlacementOfTrackingElement (placement = 'bottom-start', trac
}
}
if (trackedRect[direction] >= trackingRect[lengthToCompare[direction]]) {
return direction + '-' + newPosition
return newPosition ? (direction + '-' + newPosition) : direction
} else if (trackedRect[oppositeDirection[direction]] >= trackingRect[lengthToCompare[direction]]) {
if (position) {
return `${oppositeDirection[direction]}-${newPosition}`
} else return oppositeDirection[direction]
} else {
return direction + '-' + newPosition
return newPosition ? (direction + '-' + newPosition) : direction
}
// else {
// const [direction1, direction2] = adjacentDirections[direction]
@ -157,7 +157,7 @@ function calcPlacementTransform (placement, activatorRect, contentRect, flip) {
const adjustedPlacement = getAdjustedPlacementOfTrackingElement(placement, trackedRect, trackingRect, flip)
const suggesetedTransfromOrigin = getTransformOriginByPlacement(adjustedPlacement)
const position = getPosition(adjustedPlacement, trackedRect, trackingRect)
return [position, suggesetedTransfromOrigin]
return [position, suggesetedTransfromOrigin, adjustedPlacement]
}
export default calcPlacementTransform