-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Popover: Refactor to render using React portals #2160
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2160 +/- ##
==========================================
+ Coverage 24.06% 24.71% +0.65%
==========================================
Files 149 150 +1
Lines 4592 4641 +49
Branches 775 786 +11
==========================================
+ Hits 1105 1147 +42
- Misses 2946 2951 +5
- Partials 541 543 +2
Continue to review full report at Codecov.
|
0b89836
to
982eb5d
Compare
It was necessary to move click outside logic into Popover, which I'd intended to do eventually anyways, but was required to do so ahead of schedule only because otherwise the existing click outside handlers were assuming that the portaled content was "outside" and not allowing interaction within (e.g. selecting a block option from inserter menu). See 70b2298. |
c61b4bd
to
70b2298
Compare
There's some highly engineered code in this PR :) I noticed a small regression tough in the header inserter when I hit the "insert" button a second time, the popover is not closed. |
@youknowriad Yeah, this has turned into a rabbit hole 😬 I noticed your issue as well and flipped to In Progress. There's a few interesting things going on here:
|
ddae0d2
to
c4790b3
Compare
Noticing positioning was off on mobile, I started down another rabbit hole of fixing styling, noting an interesting gotcha that avoiding the style cascade is that assumptions about box sizing no longer hold true (i.e. need to apply The result of the work hopefully pays off. Compared to master, the height of the header inserter is more correct (5d2f030) and we restore the arrow, correctly positioned under the "+" icon:
cc @jasmussen for a style audit (and/or criticism on my desktop-first media query 😲 ) |
Visually I think this looks great 👍👍!
Can you elaborate? ;) Not sure what to look for. |
Just a single selector using the inverse of the medium breakpoint since it'd be unrealistic to unset those properties in the reverse case. |
7db7f8e
to
c5fa2f1
Compare
Ooooh dang, that's controversial! Our mixin is decidedly mobile first and here you go and except to that rule 🤘 (It's fine, I kinda expected we'd need to do this at some point :) ) |
@youknowriad Pulling out of commit comment, since it'll be lost on rebase:
I see it being a common pain point, but at the same time, it should be the expected behavior. If I render a child and bind an event to the parent, I should expect that event occurring on the child to bubble to the parent. It's in these specific use-cases cases in which we have button toggling mixed with click outside where it gets particularly sticky. One uncertainty I have on second glance is if we might just apply event handlers to the Popover's anchor (span) node instead of the portal-ed node, since the same bubbling behavior will cause events to occur on the |
bc87270
to
afda50c
Compare
Popover: Avoid close if click outside occurs in anchor parent Popover: Stop propagation in visibility button popover Amazingly, events still propagate from within a portaled node to its parent elements, likely because of React's synthetic events Inserter: Close popover by click outside Post Visibility: Close popover by click outside
Icon button size was used as a stand-in for the input size. Use expected input size instead
afda50c
to
ecb7c70
Compare
This pull request seeks to leverage React portals — a new (unstable) feature introduced in React 16 — to render the existing
Popover
component. The concept of portals has existed previously in the React ecosystem, through works such as React-portal or Calypso'sRootChild
component. The idea is that the rendering of the component occurs elsewhere in the DOM, usually at the root (body) element. This has a few benefits:div
cannot be a descendant ofbutton
)See included changes to existing Popover usage in PostVisibility as an example of the simplification permitted by the second of these benefits.
Testing instructions:
Verify that there are no regressions in the behavior of Popover controls, currently present in:
Of note, the content inserter should demonstrate "bounds flipping" behavior. It should try to open upwards (on Demo content where scroll exists), else downward if space does not permit (on New post without any content).
Ensure that unit tests pass: