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

Commit 5a56a88

Browse files
committed
fix(datepicker): fix not closing on body-click on iOS Safari. Fixes
1 parent 037e376 commit 5a56a88

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/components/datepicker/datePicker.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@
166166
/** @final */
167167
this.$$rAF = $$rAF;
168168

169+
/**
170+
* The root document element. This is used for attaching a top-level click handler to
171+
* close the calendar panel when a click outside said panel occurs. We use `documentElement`
172+
* instead of body because, when scrolling is disabled, some browsers consider the body element
173+
* to be completely off the screen and propagate events directly to the html element.
174+
* @type {!angular.JQLite}
175+
*/
176+
this.documentElement = angular.element(document.documentElement);
177+
169178
/** @type {!angular.NgModelController} */
170179
this.ngModelCtrl = null;
171180

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

549561
window.addEventListener('resize', this.windowResizeHandler);
@@ -559,7 +571,7 @@
559571
this.calendarPaneOpenedFrom = null;
560572
this.$mdUtil.enableScrolling();
561573

562-
document.documentElement.removeEventListener('click', this.bodyClickHandler);
574+
this.documentElement.off('click touchstart', this.bodyClickHandler);
563575
window.removeEventListener('resize', this.windowResizeHandler);
564576
}
565577
};

0 commit comments

Comments
 (0)