4

How can I add a class to react-day-picker's today button?

It seems to be possible from the documentation: http://react-day-picker.js.org/api/DayPicker#classNames

const dayPickerClassNames = { todayButton: 'newClass' };

<DayPicker
  classNames={dayPickerClassNames}
/>

However Im getting an error:

Warning: Failed prop type: The prop `classNames.day` is marked as required in `DayPicker`, but its value is `undefined`.
Evanss
  • 23,390
  • 94
  • 282
  • 505

3 Answers3

2

According to the API, it expects the following keys (ie, it needs the container, wrapper, .. months.. month.. day.. etc. keys), but you are only providing the todayButton key/value, apparently you need to provide each key/value pair.

You should be able to import the default classNames object, and then just update the todayButton value like so:

import classNames from '../classNames' // this path is probably not correct

const dayPickerClassNames = { ...classNames, todayButton: 'newClass' };

<DayPicker
  classNames={dayPickerClassNames}
/>
sme
  • 4,023
  • 3
  • 28
  • 42
1
const defaultClassNames = DayPicker.defaultProps.classNames,
      newClassNames = { ...datePickerClassNames,
                        container: `${defaultClassNames.container} MY_CONTAINER`
                      };

...

<DayPicker classNames={dayPickerClassNames}/>

I'd recommend appending the default class with your own as in the example above the default container class appended with MY_CONTAINER class.

molexi
  • 530
  • 5
  • 13
0

I believe it may just be parsing the word day and looking for a className for that parsed day******* I think I would just try defining the key:value relationship as they have in their documentation.

// const dayPickerClassNames = { todayButton: 'newClass' };

<DayPicker
  classNames={ todayButton: 'newClass' }
/>
  • Nope, this crashes my app: imports/client/Pages/Events/EventsPage.js:258:42: Unexpected token, expected } (258:42) – Evanss Jan 11 '18 at 15:34
  • It needs to be `classNames={ { todayButton: 'newClass' } }` for it not to crash – sme Jan 22 '18 at 10:36