在Material UI日期选择器中突出显示周末(周六和周日)

时间:2020-04-29 13:28:52

标签: reactjs datepicker material-ui

我有要求,我希望我的日期选择器突出显示周末,即星期六和星期日。我一直在使用Material-Ui-datepicker https://material-ui-pickers.dev/demo/datepicker。我尝试了各种方法,但是没有用。请任何人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

您可以使用renderDay道具。它允许自定义任何一天。

这是如何更改随机日期显示的官方示例。基本上,您需要在周末更改外观。 https://material-ui-pickers.dev/demo/datepicker#customization

v3的功能示例

renderDay={(day, selected, dayComponent) => { 
  if (isWeekend(day)) {
    return React.cloneElemnt(dayComponent, { className: 'your-css' })
  } 

  return dayComponent
}

v4的功能示例

renderDay={(day, selected, DayProps) => { 
  if (isWeekend(day)) {
    return <Day {...DayProps} className={clsx(DayProps.classname, 'your-css')} /> 
  } 

  return <Day {...DayProps} />
}