Skip to content

Commit

Permalink
[DatePicker] fix onChange on month change after initial day selection (
Browse files Browse the repository at this point in the history
…#3343)

* fix onChange doesn't fire on month change after initial day selection
Fixes #3340

* change !== to != operator

* add test onChange fired when month is changed for uncontrolled datepicker
  • Loading branch information
EndiM authored and giladgray committed Feb 7, 2019
1 parent a44ce29 commit 6b607f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/datetime/src/datePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class DatePicker extends AbstractPureComponent<IDatePickerProps, IDatePic
selectedDay: day.getDate(),
});
}
if (this.state.value == null || this.state.value.getMonth() !== day.getMonth()) {
if (this.state.value != null && this.state.value.getMonth() !== day.getMonth()) {
this.ignoreNextMonthChange = true;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/datetime/test/datePickerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ describe("<DatePicker>", () => {
assert.isTrue(onChange.calledOnce);
});

it("onChange fired when month is changed", () => {
const onChange = sinon.spy();
const { getDay, clickNextMonth } = wrap(<DatePicker onChange={onChange} />);
assert.isTrue(onChange.notCalled);
getDay().simulate("click");
assert.isTrue(onChange.calledOnce, "expected onChange called");
clickNextMonth();
assert.isTrue(onChange.calledTwice, "expected onChange called again");
});

it("selected day updates are automatic", () => {
const { assertSelectedDays, getDay } = wrap(<DatePicker />);
assertSelectedDays();
Expand Down

1 comment on commit 6b607f3

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[DatePicker] fix onChange on month change after initial day selection (#3343)

Previews: documentation | landing | table

Please sign in to comment.