Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(datepicker): fix not closing on body-click on iOS Safari. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Dec 2, 2015
1 parent 037e376 commit 5a56a88
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/datepicker/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@
/** @final */
this.$$rAF = $$rAF;

/**
* The root document element. This is used for attaching a top-level click handler to
* close the calendar panel when a click outside said panel occurs. We use `documentElement`
* instead of body because, when scrolling is disabled, some browsers consider the body element
* to be completely off the screen and propagate events directly to the html element.
* @type {!angular.JQLite}
*/
this.documentElement = angular.element(document.documentElement);

/** @type {!angular.NgModelController} */
this.ngModelCtrl = null;

Expand Down Expand Up @@ -543,7 +552,10 @@
// click, we don't want it to be immediately propogated up to the body and handled.
var self = this;
this.$mdUtil.nextTick(function() {
document.documentElement.addEventListener('click', self.bodyClickHandler);
// Use 'touchstart` in addition to click in order to work on iOS Safari, where click
// events aren't propogated under most circumstances.
// See http://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
self.documentElement.on('click touchstart', self.bodyClickHandler);
}, false);

window.addEventListener('resize', this.windowResizeHandler);
Expand All @@ -559,7 +571,7 @@
this.calendarPaneOpenedFrom = null;
this.$mdUtil.enableScrolling();

document.documentElement.removeEventListener('click', this.bodyClickHandler);
this.documentElement.off('click touchstart', this.bodyClickHandler);
window.removeEventListener('resize', this.windowResizeHandler);
}
};
Expand Down

0 comments on commit 5a56a88

Please sign in to comment.