fix(placeble):adjustedPosition

This commit is contained in:
songwanli2025@163.com 2020-01-13 17:19:36 +08:00
parent e5cccafc18
commit d556810144
2 changed files with 7 additions and 5 deletions

View File

@ -205,6 +205,7 @@ export default {
updatePosition (el, cb) {
if (!this.active && !this.show) return
this._getTrackingElement()
this.trackingElement.style.position = 'absolute'
if (this.manuallyPositioned) {
if (!this.trackingElement) {
console.error('[naive-ui/placeable/updatePosition]: trackingElement not found!')
@ -218,6 +219,10 @@ export default {
}
}
const activatorRect = getActivatorRect(this.manuallyPositioned, this.x, this.y, this.trackedElement)
const contentInner = getContentInner(this)
if (this.widthMode === 'activator' && contentInner) {
contentInner.style.minWidth = activatorRect.width + 'px'
}
const contentBoundingClientRect = {
width: this.trackingElement.offsetWidth,
height: this.trackingElement.offsetHeight
@ -230,10 +235,6 @@ export default {
offset = getPositionInAbsoluteMode(adjustedPlacement)
}
this.setOffsetOfTrackingElement(offset, suggestedTransformOrigin)
const contentInner = getContentInner(this)
if (this.widthMode === 'activator' && contentInner) {
contentInner.style.minWidth = activatorRect.width + 'px'
}
if (el && cb) {
cb(el, activatorRect, contentBoundingClientRect)
}

View File

@ -57,7 +57,8 @@ export function getAdjustedPlacementOfTrackingElement (placement = 'bottom-start
let adjustedPosition = position
if (position) {
const adjacentPositionDirection = positionDirections[placement]
if (trackedRect[adjacentPositionDirection] + trackedRect[lengthToCompare[adjacentPositionDirection]] <= trackingRect[lengthToCompare[adjacentPositionDirection]]) {
if (trackedRect[adjacentPositionDirection] + trackedRect[lengthToCompare[adjacentPositionDirection]] <= trackingRect[lengthToCompare[adjacentPositionDirection]] &&
trackingRect[lengthToCompare[adjacentPositionDirection]] > trackedRect[lengthToCompare[adjacentPositionDirection]]) {
adjustedPosition = oppositePosition[position]
}
}