猿问

如何禁用今天之前的日期 React?

我正在尝试禁用今天之前的日期,因此无法选择它。代码如下:https://codesandbox.io/s/simple-react-calendar-r1h3b?file=/src/calendar.tsx

如何实施?


ABOUTYOU
浏览 84回答 1
1回答

aluckdog

我在这里禁用了过去的日期:https://codesandbox.io/s/simple-react-calendar-1n9zk?file=/src/calendar.tsx:2706-2718const Day = styled.div`// ...&nbsp; ${props =>&nbsp; &nbsp; &nbsp; props.isPast &&&nbsp; &nbsp; &nbsp; css`&nbsp; &nbsp; &nbsp; &nbsp; color: #eee;&nbsp; &nbsp; &nbsp; &nbsp; pointer-events: none;&nbsp; &nbsp; &nbsp; `}// ...`export function Calendar() {// ...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<Day&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key={index}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isToday={d === today.getDate()}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isPast={new Date(year, month, d) < today}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isSelected={d === day}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onClick={() => setDate(new Date(year, month, d))}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {d > 0 ? d : ''}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </Day>// ...}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答