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

Create a portal to render the calendar #91

Closed
amaury1093 opened this issue Aug 21, 2018 · 10 comments
Closed

Create a portal to render the calendar #91

amaury1093 opened this issue Aug 21, 2018 · 10 comments
Labels
enhancement New feature or request fresh

Comments

@amaury1093
Copy link

Right now, when I click on the input, the calendar's HTML is rendered next to the input element.

It would be good render it inside a Portal (https://reactjs.org/docs/portals.html), so that it doesn't interfere with the styling of the input element's container.

@wojtekmaj
Copy link
Owner

wojtekmaj commented Aug 23, 2018

This makes positioning very tricky. I personally had tons of issues with such solutions in popups and other non-body containers.

Additionally, in case someone would use React-Calendar independently, this could create styling problems for them.

I'd need to give it a thought!

@ur92
Copy link

ur92 commented Oct 15, 2018

Had a similar problem here.

I try to use the datePicker inside overflow:hidden container so when I open the calendar popup, obviously, the popup is partially hidden and doesn't shown as expected.
With portal, or even a lighter option - to able to render the calendar popup under body container, will be really helpful.

Thanks!

@wojtekmaj
Copy link
Owner

You could use position: fixed to let the calendar render regardless of overflow: hidden but I don't know if that will be sufficient for your app.

@asvetliakov
Copy link

Hacky workaround:

class MyDatePicker extends ReactDatePicker {
  renderCalendar() {
    const elem = super.renderCalendar();
    if (!elem) { return null; }
    return (
      <Popover
         active={this.state.isOpen}
         targetEl={this.props.name}
      >
        {elem}
      </Popover>
    );
  }
}

Popover (or whatever) is custom component which renders child through portal (this.props.name used as id to obtain element dimensions). Hope you won't rename renderCalendar or isOpen state prop at some time 😄

@gyto23
Copy link

gyto23 commented Apr 16, 2020

@wojtekmaj I would suggest to implement both option in the calendar render:

  1. via existing way
  2. via portal

As for good example, react-select uses those two types of render, you just have to select the prop to do it

You could use position: fixed to let the calendar render regardless of overflow: hidden but I don't know if that will be sufficient for your app.

@jiangyh1024
Copy link

@asvetliakov there is no renderCalendar method

@jiangyh1024
Copy link

finally, I found a solution to solving this problem

using react-calendar and wrap it into 'popover' which is from 'material-ui'

image

works like a charm

image

@gius
Copy link

gius commented Mar 3, 2021

You could use position: fixed to let the calendar render regardless of overflow: hidden but I don't know if that will be sufficient for your app.

@wojtekmaj Could you please describe how to use it? Or do you just mean to set fixed on the date picker so that it does not scroll with the other content?

@wojtekmaj
Copy link
Owner

@gius

Or do you just mean to set fixed on the date picker so that it does not scroll with the other content?

That's what I meant.

@craghagBg
Copy link

ReactDatePicker

I tried with position fixed and dynamically setting top and left in the onCalendarOpen, but override my styles :(

@github-actions github-actions bot added the stale label Mar 21, 2022
Repository owner deleted a comment from github-actions bot Mar 21, 2022
@wojtekmaj wojtekmaj added enhancement New feature or request fresh and removed stale labels Mar 21, 2022
wojtekmaj added a commit that referenced this issue Mar 21, 2022
wojtekmaj added a commit that referenced this issue Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fresh
Projects
None yet
Development

No branches or pull requests

8 participants