From cd3f53889e40bc09ec1e921193b7cec7ba9e6a46 Mon Sep 17 00:00:00 2001 From: Max Dubrinsky Date: Wed, 8 Mar 2017 11:17:23 -0500 Subject: [PATCH 1/2] Allow 'today' modifier to override default --- src/DayPicker.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/DayPicker.js b/src/DayPicker.js index 4ca740c658..1da83e1cf6 100644 --- a/src/DayPicker.js +++ b/src/DayPicker.js @@ -421,17 +421,15 @@ export default class DayPicker extends Component { return React.cloneElement(navbarElement, props); } renderDayInMonth(day, month) { - let dayModifiers = []; - if (DateUtils.isSameDay(day, new Date())) { - dayModifiers.push(this.props.classNames.today); + const { today } = this.props.classNames; + const propModifiers = Helpers.getModifiersFromProps(this.props); + const dayModifiers = Helpers.getModifiersForDay(day, propModifiers); + if (DateUtils.isSameDay(day, new Date()) && !propModifiers.hasOwnProperty(today)) { + dayModifiers.push(today); } if (day.getMonth() !== month.getMonth()) { dayModifiers.push(this.props.classNames.outside); } - dayModifiers = [ - ...dayModifiers, - ...Helpers.getModifiersForDay(day, Helpers.getModifiersFromProps(this.props)), - ]; const isOutside = day.getMonth() !== month.getMonth(); let tabIndex = null; From 97c1c2f881c3da1faec98a43dba2445099b8885a Mon Sep 17 00:00:00 2001 From: Max Dubrinsky Date: Wed, 8 Mar 2017 15:20:25 -0500 Subject: [PATCH 2/2] Syntax recommendations and test case --- src/DayPicker.js | 6 +++--- test/daypicker/modifiers.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/DayPicker.js b/src/DayPicker.js index 1da83e1cf6..4ffe2e1d7a 100644 --- a/src/DayPicker.js +++ b/src/DayPicker.js @@ -421,11 +421,11 @@ export default class DayPicker extends Component { return React.cloneElement(navbarElement, props); } renderDayInMonth(day, month) { - const { today } = this.props.classNames; const propModifiers = Helpers.getModifiersFromProps(this.props); const dayModifiers = Helpers.getModifiersForDay(day, propModifiers); - if (DateUtils.isSameDay(day, new Date()) && !propModifiers.hasOwnProperty(today)) { - dayModifiers.push(today); + if (DateUtils.isSameDay(day, new Date()) && + !Object.prototype.hasOwnProperty.call(propModifiers, this.props.classNames.today)) { + dayModifiers.push(this.props.classNames.today); } if (day.getMonth() !== month.getMonth()) { dayModifiers.push(this.props.classNames.outside); diff --git a/test/daypicker/modifiers.js b/test/daypicker/modifiers.js index 47f03e094f..d92904700b 100644 --- a/test/daypicker/modifiers.js +++ b/test/daypicker/modifiers.js @@ -65,4 +65,20 @@ describe('DayPicker’s day modifiers', () => { expect(wrapper.find('.DayPicker-Day--none')).to.have.length(0); expect(wrapper.find('.DayPicker-Day--all')).to.have.length(35); }); + it('should show "today" as something other than the current day', () => { + const newToday = new Date(); + newToday.setDate((new Date()).getDate() + 1); + newToday.setMonth((new Date()).getMonth()); + + const modifiers = { + today: newToday, + }; + const wrapper = mount( + , + ); + expect(wrapper.find('.DayPicker-Day--today')).to.have.text(newToday.getDate()); + }); });