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

Add appendToBody and disableScroll props #1069

Merged
merged 17 commits into from
Apr 12, 2018

Conversation

joaovieira
Copy link
Contributor

Fixes #273

This adds the ability to have the day picker render outside of the scrolling container instead of being clipped.

It uses the same Portal as the portal variations, but positions the picker next to the inputs via hardware-accelerated CSS translate (keeping the top/bottom for relative positioning).

On top of that, I've decided to disable the scroll in this situation to avoid the picker being displayed when the input goes "out-of-bounds"/overflows the parent container, in case we scroll the picker with the input (as Tether/Popper does).

I've also decided to add a disableScroll with the same behaviour for non-detached pickers.

If you agree with this approach I'll continue to add tests.

Note One issue is that the anchors are rendered with the input instead of the picker, so the z-index context is different. I feel this is odd and the anchors should be part of the picker/popup. Though this is a much bigger change. Let me know what you think.

Before

screen shot 2018-03-12 at 11 49 24

After

react-dates__appendtobody

Problem with a detached scrolling picker

screen shot 2018-03-12 at 11 55 01

@coveralls
Copy link

coveralls commented Mar 12, 2018

Coverage Status

Coverage decreased (-1.6%) to 84.85% when pulling 4157e98 on joaovieira:appendToBody into d18da3b on airbnb:master.

@joaovieira
Copy link
Contributor Author

You can try it with npm i joaovieira/react-dates#appendToBody-release

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

This is really well written! This seems like a great addition to our API @joaovieira. Sorry for the delay in reviewing!

As for your comment about the anchors:

Note One issue is that the anchors are rendered with the input instead of the picker, so the z-index context is different. I feel this is odd and the anchors should be part of the picker/popup. Though this is a much bigger change. Let me know what you think.

I would say that would be part of a different change. I incorporated the anchor into the input because I wanted to positioning to be consistent with whichever DateInput was selected, regardless of how they were styled and this helped us accomplish that. We can def revisit that implementation.

My only comment is really to write a few more comments on the disableScroll utility because it's not immediately clear to me what is considered a scroll ancestor.

Other than that and some tests, this is awesome!

@@ -0,0 +1,36 @@
function getScrollParent(node, rootNode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you leave a comment as to what the scroll parent is? It seems like this will grab a modal body if that's the source of the picker, but I'm not entirely understanding how.

});

toggle(true);
return () => toggle(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very clever :)

@joaovieira
Copy link
Contributor Author

Great! Thanks for having a look @majapw. Will look into this later today:

  • Add tests
  • Document new props
  • Investigate and start new PR to move anchors to popup

@joaovieira
Copy link
Contributor Author

@majapw I've added as much tests as I could. This a feature that is tied with the DOM, hence most of the tests require a browser and/or mounting (mocking all window/document would be too complex and/or tie the tests with the implementation even more). Thus, I've opened #1109 to fix Karma and ensure browser tests are mandatory in CI. Let me know your thoughts.

Copy link
Collaborator

@majapw majapw left a comment

Choose a reason for hiding this comment

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

This is fantastic! :) I have one comment (and we can address it in a follow-up/I can make the change if necessary) but I think this is great! Thank you so much for the thorough commenting/test coverage!

* - it is allowed to scroll via CSS ('overflow-y' not visible or hidden);
* - and its children/content are "bigger" than the node's box height.
*
* The root of the document always scrolls by default.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you! This makes it super clear. :)

}

return {
transform: `translateX(${offsetX}px) translateY(${offsetY}px)`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to use translate3D(${offsetX}px, ${offsetY}px, 0) here for performance reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Thought all CSS transforms were already hardware accelerated. I can do it. Thanks :)

@majapw
Copy link
Collaborator

majapw commented Apr 12, 2018

Sweet, I'll merge this in after tests pass!

@majapw majapw merged commit c646fc8 into react-dates:master Apr 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants