首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在react-calendar中设置单击日期的样式?

如何在react-calendar中设置单击日期的样式?
EN

Stack Overflow用户
提问于 2021-05-08 12:39:11
回答 1查看 56关注 0票数 0

我正在使用react-calendar,并试图在点击后设置特定日期的样式,但我只能找到如何设置整个月的样式。我试着研究是否可以包装一个在div中单击的日期,并将该div分配给一个类,但我找不到这样做的方法。还有其他想法吗?

代码语言:javascript
复制
export const CalendarPage = () =>  {
  const datesToAddClassTo = ["Thu May 06 2021 00:00:00 GMT-0400 (Eastern Daylight Time)"];

  function tileClassName({date, view) {
      // Check if a date React-Calendar wants to check is on the list of dates to add class to
    if (view === 'month') {
      if (datesToAddClassTo[0] === date.toString()) {
        console.log("Match found!!!!!");
        return 'myClassName';
      }
    }
  }

  const [value, setValue] = useState(new Date());
  
  function onChange(nextValue) {
    setValue(nextValue);
  }

  return (
    <Calendar
      onChange={onChange}
      value={value}
      tileClassName={tileClassName}
    />
  );
EN

回答 1

Stack Overflow用户

发布于 2021-05-08 16:41:38

尝试将其更改为:

代码语言:javascript
复制
function tileClassName(data) {
    const { _, date, view } = data;

    // Check if a date React-Calendar wants to check is on the list of dates to add class to
    if (view === 'month') {
        if (datesToAddClassTo[0] === date.toString()) {
            console.log("Match found!!!!!");
            return 'myClassName';
        }
    }
}

然后为.myClassName添加样式,如果它不适用-添加!important属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67444142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档