-
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 anchored popover top position when document is scrollable #250
Fix anchored popover top position when document is scrollable #250
Conversation
Anchored popover is a <Popover> wrapped with two HOCs: `closable()(anchored()(Popover)` Before this commit it will form following DOM structure: ```html <body> <div class="gyp-base-layer"> <div class="gyp-closable> <div class="gyp-popover gyp-popover--top"> </div> </div> </body> ``` `gyp-popover` is absolutely positioned, with `top` value which is relative to its document top left corner. `gyp-closable` is `position: fixed` with `width: 100vw` and `height: 100vh`. It works when document is too short to scroll, such as previous storybook doc canvas. But when the element triggering popover is over the screen(i.e. we have to scroll to click it), the position of anchored popover will be wrong because the `position: absoulte` of `gyp-popover` is relative to `gyp-closable`, which is `position: fixed`, so the `top` value is wrong. The position of `gyp-popover` should always be relative to the document. So in this fix we change the `closable` HOC code to change DOM structure as: ```html <body> <div class="gyp-base-layer"> <div class="gyp-closable" /> <div class="gyp-popover" /> </div> </body> ``` Let the `gyp-popover` be relative to `gyp-base-layer`, which is absolute to `document.body`. Note that this bug won't happen on Cloud2 since on Cloud2 the `document.body` height is always `100vh`, which is not scrollable.
@@ -85,7 +85,7 @@ it('intercepts event propagation if instructed', () => { | |||
<ClosableFoo closable={{ stopEventPropagation: true }} /> | |||
</div> | |||
); | |||
wrapper.find('div#foo').simulate('click'); | |||
wrapper.find('div.gyp-closable').simulate('click'); |
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.
This is because wrapped component (#foo
) is not the child of div.gyp-closable
now. To test stopPropagtion
we have no choice but testing on div.closable
itself.
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 catch! Thanks for finding this out ✨
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.
LGTM
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
As title. In #249 I mentioned this bug.
Anchored popover is a wrapped with two HOCs:
closable()(anchored()(Popover)
Before this commit it will form following DOM structure:
gyp-popover
is absolutely positioned, withtop
value whichis relative to its document top left corner.
gyp-closable
isposition: fixed
withwidth: 100vw
andheight: 100vh
.It works when document is too short to scroll, such as previous
storybook doc canvas. But when the element triggering popover is
over the screen(i.e. we have to scroll to click it), the position
of anchored popover will be wrong because the
position: absoulte
of
gyp-popover
is relative togyp-closable
, which isposition: fixed
, so thetop
value is wrong.The position of
gyp-popover
should always be relative to thedocument. So in this fix we change the
closable
HOC code to changeDOM structure as:
Let the
gyp-popover
be relative togyp-base-layer
, which is absoluteto
document.body
.Note that this bug won't happen on Cloud2 since on Cloud2 the
document.body
height is always100vh
, which is not scrollable.And, this fix only affect
<Popover>
component because currentlyonly
<Popover>
using theclosable
mixin.Changes
/packages/core/src/mixins/closable/
DOM structure.intercepts event propagation if instructed
test to match the fix.UI screenshots
You can verify them in popover storybook doc on
feature/core-docs-pt4
and this branch respectively.Before the fix:
After the fix:
Risk
Might influence cloud2 popover UI. Though I have manually tested this and it looks fine.
TODOs