-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix popover placement when there is no enough space on top or bottom of content #303
Conversation
packages/core/src/Popover.js
Outdated
<div className={BEM.container}> | ||
<div | ||
className={BEM.container} | ||
style={{ maxHeight: remainingSpace ? remainingSpace - popoverPadding : undefined }} |
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.
remainingSpace
是指扣掉箭頭後剩餘的高度,因此還要再扣掉 Popover 自身的 padding
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.
有點隱晦,覺得可以一起放進註解
positionTop = anchorOffsetTop - selfHeight; | ||
// Make sure user can see whole wrapped component when placement is TOP. | ||
positionTop = Math.max(anchorOffsetTop - selfHeight, 0); |
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.
確保當 placement 為 TOP 時,Popover 最高只會被擺到畫面上緣。如果是負的有可能會看不到 Popover 上半部。
packages/core/src/Popover.js
Outdated
@@ -45,6 +46,8 @@ function Popover({ | |||
onClick(event); | |||
}; | |||
|
|||
const popoverPadding = 24; |
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.
覺得 popoverPadding 可以移到 function 外宣告
然後直接在這裡算 maxHeight
const maxHeight = remainingSpace ? remainingSpace - popoverPadding : undefined;
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.
也可,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.
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.
expected | defaultVal | situation | anchorTop | anchorHeight | selfHeight | remainingSpace | ||
${TOP} | ${TOP} | ${'enough'} | ${120} | ${30} | ${100} | ${120} | ||
${BOTTOM} | ${TOP} | ${'not enough for top'} | ${90} | ${30} | ${100} | ${648} | ||
${TOP} | ${BOTTOM} | ${'not enough for bottom'} | ${600} | ${100} | ${100} | ${600} | ||
${BOTTOM} | ${BOTTOM} | ${'enough'} | ${300} | ${100} | ${100} | ${368} | ||
${BOTTOM} | ${BOTTOM} | ${'not enough for both, but bottom is larger'} | ${300} | ${100} | ${400} | ${368} | ||
${TOP} | ${BOTTOM} | ${'not enough for both, but top is larger'} | ${450} | ${100} | ${500} | ${450} |
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.
nice tests 👍
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.
我覺得看起來沒問題!
Purpose
修正當 placement 設定為向下 (
bottom
) 的 popover 下方空間不足時往上長,結果導致看不到 popover 上半部的問題。這是因為現在
anchored
的邏輯,在原本的 placement 向下且空間不足時,就會往上。因此當 popover 的內容沒有出現捲軸(不超過max-height
),但又比上方空間長時,popover 上面的東西就點不到。解法:當 popover 的 placement 設定為向下,且下方和上方的空間都不足時,還是向下長。缺點是有機會破圖,但相對不能按應該還是好些。根據後續的討論,改成在上下都不夠顯示 popover 時,用空間較足夠的那邊作為 placement。並且計算剩餘空間給下面的
<Popover>
作為max-height
來確保不會高到破版。Changes
Risk
會影響到
<Tooltip>
和<Popover>
在 placement 設為 bottom 且上下空間都不夠時的行為,其餘不影響。TODOs