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.

SingleDatePicker with numberOfMonths={1} not displaying month table

See original GitHub issue

I tried to implement the SingleDatePicker wrapped in the same way found in the examples. This is the result: screen shot 2016-11-07 at 8 17 55 pm

For some reason the current month table seems to be positioned outside the container. The month previous to the current month (October) is rendered in the position where the current month(November) should be , and is hidden because of the numberOfMonths={1} prop, therefore the white space.

This is how I’ve implemented the wrapper:

import React from 'react';
import { SingleDatePicker } from 'react-dates'
import 'react-dates/lib/css/_datepicker.css'

class SingleDatePickerWrapper extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      focused: false,
      date: null,
    };

    this.onDateChange = this.onDateChange.bind(this);
    this.onFocusChange = this.onFocusChange.bind(this);
  }

  onDateChange(date) {
    this.setState({ date });
  }

  onFocusChange({ focused }) {
    this.setState({ focused });
  }

  render() {
    const { focused, date } = this.state;

    return (
      <SingleDatePicker
        {...this.props}
        id="date_input"
        date={date}
        focused={focused}
        onDateChange={this.onDateChange}
        onFocusChange={this.onFocusChange}
      />
    );
  }
}

export default SingleDatePickerWrapper;

And this is how I’m using it:

<SingleDatePickerWrapper
              numberOfMonths={1}
 />

I’m not sure if I’m doing something wrong or if I need to pass some extra props through the wrapper in order for the component to render correctly, but I’m using it pretty much unchanged from the SingleDatePicker example. Any help would be greatly appreciated 😃

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

2reactions
eaharonoffcommented, Jul 5, 2017

Hi, I am using the DayPickerRangeController component and I am having the same issue as @7091lapS . I cloned the repo and ran the script yarn build:css to retrieve the CSS and copied it into my project. I also tried all the above recommendations to no avail. Here is what my wrapper looks like:

import React, { Component } from 'react';
import moment from 'moment';
import { DayPickerRangeController } from 'react-dates';

import { START_DATE } from './constants';

if (process.env.BROWSER) {
  require('./styles/_datepicker.css');
}

class DatePickerWrapper extends Component {

  state = {
    errorMessages: [],
    startDate: null,
    endDate: null,
    focusedInput: START_DATE
  }

  _onDateChange = ({ startDate, endDate }) => {
    this.setState({ endDate: endDate });
  }

  _onFocusChange = (focusedInput) => {
    this.setState({
      focusedInput: !focusedInput ? START_DATE : focusedInput
    });
  }

  render() {
    const {
      startDate,
      endDate,
      focusedInput
    } = this.state;

          <DayPickerRangeController
            startDate={ startDate } 
            endDate={ endDate }
            onDatesChange={ this._onDateChange } 
            focusedInput={ focusedInput } 
            onFocusChange={ this._onFocusChange } 
            numberOfMonths={ 1 }
            initialVisibleMonth={ () => moment() }
          />
      </div>
    );
  }
}

export default DatePickerWrapper;

Here is what renders: screen shot 2017-07-05 at 5 29 26 pm

Any help would be much appreciated 😃

0reactions
amlivingamlivingcommented, Jan 19, 2017

@majapw I believe #256 correctly identifies the source of the problem. The parent container needs to be text-align: left;. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SingleDatePicker with numberOfMonths={1} not displaying ...
For some reason the current month table seems to be positioned outside the container. The month previous to the current month (October) is ......
Read more >
Airbnb react date range picker only showing current month ...
After selecting start date and end date when I am re-opening the date picker the calendar shows current month instead of the selected...
Read more >
<input type="month"> - HTML: HyperText Markup Language
A Boolean attribute which, if present, means this field cannot be edited by the user. Its value can, however, still be changed from...
Read more >
Date Range Picker for Bootstrap
The Date Range Picker can be turned into a single date picker widget with only one calendar. In this example, dropdowns to select...
Read more >
Date Range Picker — JavaScript Date & Time Picker Library
* Addition: when set, show only 1 calendar with 1 month even if singleDatePicker is not set. */ singleMonthView?: boolean;. I extracted some...
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