-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 调整 absolute 下拉控制组件定位逻辑,增加容器在有无 relative 下的处理 #1987
base: dev
Are you sure you want to change the base?
Conversation
src/AnimationList/AbsoluteList.tsx
Outdated
const parent = target.parentElement | ||
|
||
if (parent && parent.tagName === 'BODY') { | ||
return document.body |
There was a problem hiding this comment.
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
src/AnimationList/AbsoluteList.tsx
Outdated
@@ -126,42 +127,85 @@ export default function<U extends {}>(List: ComponentType<U>) { | |||
const defaultContainer = getDefaultContainer() | |||
const rootContainer = container === getRoot() || !container ? defaultContainer : container | |||
const containerRect = rootContainer.getBoundingClientRect() | |||
const nearestPositionDom = this.getNearestPositionDom(rootContainer) | |||
const nearestPositionDomRect = nearestPositionDom.getBoundingClientRect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接一开始就能判断出 实际的容器 只需要计算实际的容器即可, 简单清晰一些
src/AnimationList/AbsoluteList.tsx
Outdated
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state 中存一个 offset , isRight 判断需要增加
问题描述:
下拉控制组件在指定挂载容器的同时,开启 absolute 定位功能后,可能导致下拉菜单定位计算错误。
解决方案:
增加对挂载节点的容器或祖先容器是否存在 relative 的判断,根据最近的、非 static 定位的祖先元素,计算挂载位置。