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.

How to show selected days in day picker?

See original GitHub issue

It looks like the supported way to select a day in the DayPicker is to define modifiers and change the class of the day element. When I say select a day, I mean show the day is selected in the user interface by force (in the event that we are showing edit time, we have a previously set time) or when the user is actually interacting with the DayPicker. This seems slow / inefficient because the date comparison code in the modifiers method needs to be run for each day and it looks like regardless of number of months showing, it renders 90 days (maybe the month before and month after)? So that’s 90 comparisons every time a day is tapped, a month is changed, or we forcefully set the selected date and re-render the component to reflect that. Maybe it’s just a documentation issue. Is there a better way?

Right now I do something like…

  dayClick = (date) => {
    this.setState({selectedDay: date});
  }
...
<DayPicker
  id="date_input"
  numberOfMonths={1}
  onDayClick={this.dayClick}
  modifiers={{selected: (day) => 
    day.isSame(this.state.selectedDay, 'd')}}
/>

The SingleDatePicker has a date prop for selected date but it doesn’t look like the DayPicker does.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
alpjorcommented, Jun 7, 2017

It looks to me like the modifiers that are currently passed into <DayPicker are getting lost in here: https://github.com/airbnb/react-dates/blob/master/src/components/CalendarMonthGrid.jsx#L223 and again here: https://github.com/airbnb/react-dates/blob/master/src/components/CalendarMonth.jsx#L142

why would we need to pass modifiers that are scoped to a month name?

1reaction
majapwcommented, Apr 1, 2017

So sorry for the delayed response. 😢 I definitely just missed some issues when things got crazy at work, and this was one of them, unfortunately. Thanks for responding anyways!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selecting Days - React DayPicker
Selecting Days. DayPicker supports 3 built-in selection modes to display days as selected. Enable a selection mode by setting the mode prop.
Read more >
How to show selected days in day picker? · Issue #320 - GitHub
It looks like the supported way to select a day in the DayPicker is to define modifiers and change the class of the...
Read more >
How to pass an array of dates to selectedDays in react-day ...
The component is passed the 'dateItems' array of dates, and I would like to be able to render this array of dates. At...
Read more >
How to use the react-day-picker.DateUtils.isSameDay function ...
To help you get started, we've selected a few react-day-picker examples, based on popular ways it is used in public projects. Secure your...
Read more >
gpbl/react-day-picker - Gitter
yes, see http://react-day-picker.js.org/examples/?overlay ... sorry the selectedDays not the value ... Is there a way to focus on a specific day?
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