Skip to content

feat: 调整 absolute 下拉控制组件定位逻辑,增加容器在有无 relative 下的处理#1987

Open
KMS-Bismarck wants to merge 7 commits intodevfrom
fix-bug-select-absolute
Open

feat: 调整 absolute 下拉控制组件定位逻辑,增加容器在有无 relative 下的处理#1987
KMS-Bismarck wants to merge 7 commits intodevfrom
fix-bug-select-absolute

Conversation

@KMS-Bismarck
Copy link
Contributor

问题描述:
下拉控制组件在指定挂载容器的同时,开启 absolute 定位功能后,可能导致下拉菜单定位计算错误。

解决方案:
增加对挂载节点的容器或祖先容器是否存在 relative 的判断,根据最近的、非 static 定位的祖先元素,计算挂载位置。

const parent = target.parentElement

if (parent && parent.tagName === 'BODY') {
return document.body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

逻辑错误 当 target 为 body 下一层的时候 不是无条件返回 body ,应该判断target 得 position

const rootContainer = container === getRoot() || !container ? defaultContainer : container
const containerRect = rootContainer.getBoundingClientRect()
const nearestPositionDom = this.getNearestPositionDom(rootContainer)
const nearestPositionDomRect = nearestPositionDom.getBoundingClientRect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接一开始就能判断出 实际的容器 只需要计算实际的容器即可, 简单清晰一些

overdoc = pos.left - containerRect.left + width + containerScroll.left > (containerRect.width || docSize.width)
overdoc =
pos.left + width + containerScroll.left - containerRect.left >
((absolute ? docSize.width : containerRect.width) || docSize.width)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接使用最终容器的width

const mergeStyle = Object.assign({}, style, this.state.overdoc ? getOverDocStyle(this.isRight()) : undefined)
const mergeStyle = Object.assign(
{},
style,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state 中存一个 offset , isRight 判断需要增加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants