From e066e195e0a8162c40b1b27c23581be62cefcd6c Mon Sep 17 00:00:00 2001 From: "songwanli2025@163.com" Date: Thu, 2 Jan 2020 14:19:27 +0800 Subject: [PATCH] fix(popover): fix popover arrow direction --- packages/common/Popover/src/PopoverContent.js | 2 +- packages/mixins/placeable.js | 9 ++++----- packages/utils/dom/calcPlacementTransform.js | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/common/Popover/src/PopoverContent.js b/packages/common/Popover/src/PopoverContent.js index 7c1d7ba8f..a34c6900e 100644 --- a/packages/common/Popover/src/PopoverContent.js +++ b/packages/common/Popover/src/PopoverContent.js @@ -253,7 +253,7 @@ export default { this.active ? h('div', { attrs: { - 'n-placement': this.placement + 'n-placement': this.adjustedPlacement }, staticClass: 'n-popover-content', class: { diff --git a/packages/mixins/placeable.js b/packages/mixins/placeable.js index 547778804..28cd66d24 100644 --- a/packages/mixins/placeable.js +++ b/packages/mixins/placeable.js @@ -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 diff --git a/packages/utils/dom/calcPlacementTransform.js b/packages/utils/dom/calcPlacementTransform.js index bbdaa75b7..559ff5c22 100644 --- a/packages/utils/dom/calcPlacementTransform.js +++ b/packages/utils/dom/calcPlacementTransform.js @@ -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