question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support responsive date pickers for different screen sizes

See original GitHub issue

Hi guys, thanks for this great package!

Is there any way of having the date picker behave differently at different resolutions? Basically I want to set withPortal={true}, but only for phone screens.

One workaround I thought of was to have two DateRangePickers, each one visible only on phones, respectively larger screens, but they both get rendered exactly the same (with portal).

Is there a solution for this that I missed? (preferably not very hacky) And, if not, are multiple date pickers supported?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

16reactions
gloaeccommented, Sep 18, 2018

I dont know if this can help someone, but you can make the calendar’s width fluid using a bit of css :

.DayPicker,
.DayPicker > div,
.DayPicker > div > div,
.DayPicker_transitionContainer,
.CalendarMonth_table {
  width: 100% !important;
}

.CalendarMonthGrid {
  width: 1000% !important;
}

.CalendarMonthGrid_month__horizontal {
  width: calc(10% - 18px) !important;
}

.DayPicker_weekHeader {
  width: calc(100% - 9px) !important;
}

.CalendarDay,
.DayPicker_weekHeader_li {
  width: 14.285714286% !important;
}
3reactions
vladbalancommented, Oct 11, 2016

@majapw Thanks! matchMedia fits perfectly with the withPortal prop. Based on this we could easily set the orientation in the same manner:

const smallDevice = window.matchMedia('(max-width: 400px)').matches;
const orientation = smallDevice ? VERTICAL_ORIENTATION : HORIZONTAL_ORIENTATION;
...
<DateRangePicker 
  ...
  orientation={orientation}
  withPortal={smallDevice}
/>

Since this is a common use case it would be nice to have this documented, maybe as a best practice.

Can you clarify that point?

When trying to add 2 DateRangePickers to my component with different props:

<DateRangePicker 
  ...
  id="drp1"
  orientation={VERTICAL_ORIENTATION}
  withPortal={true}
/>
<DateRangePicker 
  ...
  id="drp2"
  orientation={HORIZONTAL_ORIENTATION}
  withPortal={false}
/>

they both get rendered the same (as if they were both set with VERTICAL_ORIENTATION and withPortal={true}.

I don’t have a need for this anymore, but if someone else experiences this, they should open a new issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support responsive date pickers for different screen sizes #108
Hi guys, thanks for this great package! Is there any way of having the date picker behave differently at different resolutions?
Read more >
Responsive datepicker calendar for mobile, desktop - Mobiscroll
View calendar demos for progressive web and hybrid apps with validation, min/max, week counter, multiple select & more. Last update: Dec 19, 2022....
Read more >
Date pickers - Material Design
Date pickers let users select a date or range of dates. They should be suitable for the context in which they appear. Date...
Read more >
Date And Time Picker - Building WordPress Since 2011
Find the best Date and Time Picker to work nice with any screen size · 1. jQuery Time Picker Add-on · 2. Bootstrap...
Read more >
Responsive Coaches toolkit: Date Time Picker control - IBM
This control is a user interface in which the user can view and enter dates and times. This control supports the Gregorian calendar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found