Skip to content
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

Merged

Conversation

chenesan
Copy link
Contributor

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:

<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:

<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.
And, this fix only affect <Popover> component because currently
only <Popover> using the closable mixin.

Changes

  • change /packages/core/src/mixins/closable/ DOM structure.
  • change closable 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:

螢幕快照 2020-02-10 上午11 48 03

After the fix:

螢幕快照 2020-02-10 上午11 44 10

Risk

Might influence cloud2 popover UI. Though I have manually tested this and it looks fine.

TODOs

  • Describe what should be done outside of this PR
  • Maybe in other PRs or some manual actions.

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');
Copy link
Contributor Author

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.

@chenesan chenesan self-assigned this Feb 10, 2020
@chenesan chenesan added the bug label Feb 10, 2020
Copy link
Contributor

@zhusee2 zhusee2 left a 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 ✨

Copy link
Contributor

@benny0642 benny0642 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tz5514 tz5514 left a comment

Choose a reason for hiding this comment

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

@chenesan chenesan merged commit 91bd428 into feature/core-docs-pt4 Feb 11, 2020
@chenesan chenesan deleted the fix/anchored-popover-not-work-in-new-storybook branch February 11, 2020 07:27
@kyoyadmoon kyoyadmoon mentioned this pull request Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants