Skip to content

Commit

Permalink
fix: dateInput popover closure on chrome when using min/max date
Browse files Browse the repository at this point in the history
  • Loading branch information
ejose19 committed Sep 7, 2020
1 parent 90db227 commit a23310b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
4 changes: 3 additions & 1 deletion packages/datetime/src/dateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ export class DateInput extends AbstractPureComponent2<IDateInputProps, IDateInpu
// Beware: this.popoverContentEl is sometimes null under Chrome
if (
relatedTarget == null ||
(this.popoverContentEl != null && !this.popoverContentEl.contains(relatedTarget))
(relatedTarget !== document.body &&
this.popoverContentEl != null &&
!this.popoverContentEl.contains(relatedTarget))
) {
this.handleClosePopover();
} else if (relatedTarget != null) {
Expand Down
14 changes: 0 additions & 14 deletions packages/datetime/test/dateInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ describe("<DateInput>", () => {
assert.isFalse(wrapper.find(Popover).prop("isOpen"));
});

it("Popover closes when first day of the month is blurred", () => {
const defaultValue = new Date(2018, Months.FEBRUARY, 6, 15, 0, 0, 0);
const wrapper = mount(<DateInput {...DATE_FORMAT} defaultValue={defaultValue} />);
wrapper.find("input").simulate("focus").simulate("blur");
// First day of month is the only .DayPicker-Day with tabIndex == 0
const tabbables = wrapper.find(Popover).find(".DayPicker-Day").filter({ tabIndex: 0 });
const firstDay = tabbables.getDOMNode() as HTMLElement;
firstDay.dispatchEvent(createFocusEvent("blur"));
// manually updating wrapper is required with enzyme 3
// ref: https://github.com/airbnb/enzyme/blob/master/docs/guides/migration-from-2-to-3.md#for-mount-updates-are-sometimes-required-when-they-werent-before
wrapper.update();
assert.isFalse(wrapper.find(Popover).prop("isOpen"));
});

it("Popover should not close if focus moves to previous day", () => {
const defaultValue = new Date(2018, Months.FEBRUARY, 6, 15, 0, 0, 0);
const wrapper = mount(<DateInput {...DATE_FORMAT} defaultValue={defaultValue} />);
Expand Down

0 comments on commit a23310b

Please sign in to comment.