0

I have tried possible ways to disable current date from React Datepicker.

Below is my code.

<SingleDatePicker
  showDefaultInputIcon
  inputIconPosition={ICON_AFTER_POSITION}
  date={input.value}
  placeholder="Move Date"
  numberOfMonths={input.numberOfMonths ? input.numberOfMonths : 1}
  focused={meta.active}
  openDirection="up"
  onDateChange={value => {
    const val = value && value.format ? value.format() : value;
    input.onChange(val);
  }}
  onFocusChange={({ focused }) => {
    if (focused) {
      input.onFocus({ focused });
      return;
    }
    input.onBlur();
  }}
/>

If anyone disabled help me.

Amruth
  • 5,792
  • 2
  • 28
  • 41
  • are you disabling based on a range or just one date? – Anup Dec 26 '17 at 09:55
  • http://airbnb.io/react-dates/?selectedKind=DRP%20-%20Day%20Props&selectedStory=with%20some%20blocked%20dates&full=0&down=1&left=1&panelRight=0&downPanel=storybook%2Factions%2Factions-panel check dis out once might solve ur usecase – Anup Dec 26 '17 at 09:56
  • yes @Anup i have to disable past days as well. so i done with the solution. thanks for suggestion. this link i have already posted in question itself. anyway thanks – Amruth Dec 26 '17 at 11:06

1 Answers1

0

Finally am able to disable today from the date picker by using isOutsideRange prop and moment.

Below is my updated code.
I have created tomorrow date first.

const tomo = moment().add(1, 'day').endOf('day');

I have enabled dates only from tomorrow using isOutsideRange.

 <SingleDatePicker
  showDefaultInputIcon
  inputIconPosition={ICON_AFTER_POSITION}
  date={input.value}
  placeholder="Move Date"
  numberOfMonths={input.numberOfMonths ? input.numberOfMonths : 1}
  focused={meta.active}
  openDirection="up"
  isOutsideRange={day => !isInclusivelyAfterDay(day, tomo)}
  onDateChange={value => {
    const val = value && value.format ? value.format() : value;
    input.onChange(val);
  }}
  onFocusChange={({ focused }) => {
    if (focused) {
      input.onFocus({ focused });
      return;
    }
    input.onBlur();
  }}
/>
Amruth
  • 5,792
  • 2
  • 28
  • 41