Как отключить даты до сегодняшнего дня React? - PullRequest
0 голосов
/ 26 мая 2020

Я пытаюсь отключить даты до сегодняшнего дня, чтобы их нельзя было выбрать. Вот код: https://codesandbox.io/s/simple-react-calendar-r1h3b?file= / src / calendar.tsx

Как это можно реализовать?

1 Ответ

0 голосов
/ 26 мая 2020

Я отключил прошлые даты здесь: https://codesandbox.io/s/simple-react-calendar-1n9zk?file= / src / calendar.tsx: 2706-2718

const Day = styled.div`
// ...

  ${props =>
      props.isPast &&
      css`
        color: #eee;
        pointer-events: none;
      `}

// ...
`
export function Calendar() {
// ...
             <Day
                key={index}
                isToday={d === today.getDate()}
                isPast={new Date(year, month, d) < today}
                isSelected={d === day}
                onClick={() => setDate(new Date(year, month, d))}
              >
                {d > 0 ? d : ''}
              </Day>
// ...
}
...