React-datepicker: TimeSelect is not being displayed properly

Created on 4 Nov 2017  路  18Comments  路  Source: Hacker0x01/react-datepicker

screen shot 2017-11-04 at 10 48 51

wontfix

Most helpful comment

Hi @Rahulkr204 sure. this works in my case

// imports
import 'react-datepicker/dist/react-datepicker.css';

...
// component
return (
    <div>
        <style>
          {`.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
            padding-left: 0;
            padding-right: 0;
          }`}
        </style>
        <DatePicker
          dateFormat="YYYY-MM-DD HH:mm"
          showTimeSelect
          timeFormat="HH:mm"
          selected={Moment(this.state.date)}
          onChange={this.onChange}
        />
    </div>
);

All 18 comments

Experience the same problem, guys

I am not even getting the time section.
screen shot 2017-11-07 at 10 23 47 am
screen shot 2017-11-07 at 10 24 18 am

I got the same problem TimeSelect is not working. Even upgrade to the ver. 0.60.0

It is temporary fix the issue:

    1.
import 'react-datepicker/dist/react-datepicker.css';
  1. add some inline styles
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
    padding-left: 0;
    padding-right: 0;
}

@orx0r Added your fix to my code, still struggling with problem. Can you share your code snippet of DatePicker component used ?

Hi @Rahulkr204 sure. this works in my case

// imports
import 'react-datepicker/dist/react-datepicker.css';

...
// component
return (
    <div>
        <style>
          {`.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
            padding-left: 0;
            padding-right: 0;
          }`}
        </style>
        <DatePicker
          dateFormat="YYYY-MM-DD HH:mm"
          showTimeSelect
          timeFormat="HH:mm"
          selected={Moment(this.state.date)}
          onChange={this.onChange}
        />
    </div>
);

Hi @orx0r
the same issue.
it's invalid the code that you show

@orx0r works like a charm, thank you!!!

@orx0r Thanks!!! Works great !! The code snippet really helped

@orx0r Perfect!!

The temp fix helped on desktop, but mobile looks like this:

screen shot 2017-12-07 at 5 15 20 pm

@bskinny129 I did this to make it work on smaller screens (probably not very elegant, but it worked)
```css
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
padding-left: unset;
padding-right: unset;
width: 100px;
}

.react-datepicker__input-container {
width:100%;
}

.react-datepicker-wrapper {
width:100%;
}

.react-datepicker {
width: 314px;
}

@willm Thank you, that really helped!

In case it helps anyone, here is my complete settings that I tried to optimize for mobile (doesn't pop up keyboard and is a little smaller to consistently fit on the screen):

```
.react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
padding-left: unset;
padding-right: unset;
width: 100px;
}
.react-datepicker__input-container, .react-datepicker-wrapper {
width:100%;
}
.react-datepicker {
width: 314px;
}
.react-datepicker .react-datepicker__day {
line-height: 1.4rem;
margin: .1rem 0.166rem;
}
.react-datepicker .react-datepicker__day-name {
line-height: 1rem;
}


popperModifiers={{
offset: {
enabled: true,
offset: '0px, 12px'
},
preventOverflow: {
enabled: true,
escapeWithReference: false,
boundariesElement: 'viewport'
}
}}
shouldCloseOnSelect={false} selected={this.state.tempDate} onChange={this.datePickerChanged}
dateFormat="M/D/YY h:mm a" timeIntervals={15} timeFormat="h:mm a" showTimeSelect />
```

@orx0r and all others guys
thanks all of you to save my days :)

for anyone who use styled-component solution
according @orx0r sol for ref

const FixDatePickerTimer = styled.span`
  & .react-datepicker__time-container .react-datepicker__time .react-datepicker__time-box ul.react-datepicker__time-list {
    padding-left: unset;
    padding-right: unset;
    width: 100px;
  }
  & .react-datepicker__input-container {
    width:100%;
  }
  & .react-datepicker-wrapper {
    width:100%;
  }
  & .react-datepicker {
    width: 314px;
  }
`;

.....
<FixDatePickerTimer>
  <DatePicker
    dateFormat="YYYY-MM-DD HH:mm"
    showTimeSelect
    timeFormat="HH:mm"
    selected={Moment(this.state.date)}
    onChange={this.onChange}
   />
</FixDatePickerTimer>

@orx0r thank you! it work now

@orx0r Thank you it worked for me

Is there going to be a more permanent fix for this? Running react-datepicker v1.6 with React 15.6.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings