Skip to content

Commit

Permalink
Merge pull request #279 from maxdubrinsky/master
Browse files Browse the repository at this point in the history
Allow 'today' modifier to override default
  • Loading branch information
gpbl authored Mar 8, 2017
2 parents f81357b + 97c1c2f commit d4ec272
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/DayPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,15 @@ export default class DayPicker extends Component {
React.createElement(navbarElement, props);
}
renderDayInMonth(day, month) {
let dayModifiers = [];
if (DateUtils.isSameDay(day, new Date())) {
const propModifiers = Helpers.getModifiersFromProps(this.props);
const dayModifiers = Helpers.getModifiersForDay(day, propModifiers);
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);
}
dayModifiers = [
...dayModifiers,
...Helpers.getModifiersForDay(day, Helpers.getModifiersFromProps(this.props)),
];

const isOutside = day.getMonth() !== month.getMonth();
let tabIndex = null;
Expand Down
16 changes: 16 additions & 0 deletions test/daypicker/modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<DayPicker
initialMonth={ new Date() }
modifiers={ modifiers }
/>,
);
expect(wrapper.find('.DayPicker-Day--today')).to.have.text(newToday.getDate());
});
});

0 comments on commit d4ec272

Please sign in to comment.