Merge pull request #25 from wanli-song/develop

fix(placeable)
This commit is contained in:
07akioni 2020-01-15 15:26:44 +08:00 committed by GitHub Enterprise
commit f6df6c90f1
4 changed files with 14 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<div
v-if="showLightBar"
class="n-base-select-menu-light-bar"
:style="{ top: `${lightBarTop}px` }"
:style="{ top: lightBarStyleTop }"
/>
</transition>
</div>

View File

@ -55,7 +55,6 @@ export default {
},
mounted () {
if (this.detached) {
this.detachTarget = document.body // getScrollParent(this.$refs.self)
this.detachContent()
if (this.active && !this.contentContainerMounted) {
this.contentContainerMounted = true

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,8 +57,14 @@ export function getAdjustedPlacementOfTrackingElement (placement = 'bottom-start
let adjustedPosition = position
if (position) {
const adjacentPositionDirection = positionDirections[placement]
if (trackedRect[adjacentPositionDirection] + trackedRect[lengthToCompare[adjacentPositionDirection]] <= trackingRect[lengthToCompare[adjacentPositionDirection]]) {
adjustedPosition = oppositePosition[position]
if (trackingRect[lengthToCompare[adjacentPositionDirection]] > trackedRect[lengthToCompare[adjacentPositionDirection]]) {
if (trackedRect[adjacentPositionDirection] + trackedRect[lengthToCompare[adjacentPositionDirection]] <= trackingRect[lengthToCompare[adjacentPositionDirection]]) {
adjustedPosition = oppositePosition[position]
}
} else if (trackingRect[lengthToCompare[adjacentPositionDirection]] < trackedRect[lengthToCompare[adjacentPositionDirection]]) {
if (trackedRect[oppositeDirection[adjacentPositionDirection]] < 0 && trackedRect[adjacentPositionDirection] > 0) {
adjustedPosition = oppositePosition[position]
}
}
}
if (trackedRect[direction] >= trackingRect[lengthToCompare[direction]]) {