如何将一个类添加到react-day-picker的今日按钮?
似乎可以从文档中找到: http://react-day-picker.js.org/api/DayPicker#classNames
const dayPickerClassNames = { todayButton: 'newClass' };
<DayPicker
classNames={dayPickerClassNames}
/>
但是我收到了错误:
Warning: Failed prop type: The prop `classNames.day` is marked as required in `DayPicker`, but its value is `undefined`.
答案 0 :(得分:1)
根据API,它需要以下键(即,它需要容器,包装器,..月......月......日等等),但是你只提供todayButton键/值,显然你需要提供每个键/值对。
您应该可以导入默认的classNames
对象,然后只需更新todayButton
值:
import classNames from '../classNames' // this path is probably not correct
const dayPickerClassNames = { ...classNames, todayButton: 'newClass' };
<DayPicker
classNames={dayPickerClassNames}
/>
答案 1 :(得分:0)
我相信它可能只是解析单词day
并为已解析的day*******
寻找一个className我想我会尝试定义他们文档中的key:value
关系
// const dayPickerClassNames = { todayButton: 'newClass' };
<DayPicker
classNames={ todayButton: 'newClass' }
/>
答案 2 :(得分:0)
const defaultClassNames = DayPicker.defaultProps.classNames,
newClassNames = { ...datePickerClassNames,
container: `${defaultClassNames.container} MY_CONTAINER`
};
...
<DayPicker classNames={dayPickerClassNames}/>
我建议在默认类中附加您自己的类,如上例中默认的 container
类附加了 MY_CONTAINER
类。