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

Commit 73c424d

Browse files
Splaktarmmalerba
authored andcommitted
fix(datepicker): auto closes in Chrome when md-open-on-focus is used (#11719)
improve event handling based on suggestions by Navid Zolghadr Fixes #11701
1 parent 74563b6 commit 73c424d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/datepicker/js/datepickerDirective.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,23 @@
530530

531531
// Add event listener through angular so that we can triggerHandler in unit tests.
532532
self.ngInputElement.on('keydown', function(event) {
533-
if (event.altKey && event.keyCode == keyCodes.DOWN_ARROW) {
533+
if (event.altKey && event.keyCode === keyCodes.DOWN_ARROW) {
534534
self.openCalendarPane(event);
535535
$scope.$digest();
536536
}
537537
});
538538

539539
if (self.openOnFocus) {
540540
self.ngInputElement.on('focus', angular.bind(self, self.openCalendarPane));
541+
self.ngInputElement.on('click', function(event) {
542+
event.stopPropagation();
543+
});
544+
self.ngInputElement.on('pointerdown',function(event) {
545+
if (event.target && event.target.setPointerCapture) {
546+
event.target.setPointerCapture(event.pointerId);
547+
}
548+
});
549+
541550
angular.element(self.$window).on('blur', self.windowBlurHandler);
542551

543552
$scope.$on('$destroy', function() {
@@ -551,7 +560,7 @@
551560
};
552561

553562
/**
554-
* Capture properties set to the date-picker and imperitively handle internal changes.
563+
* Capture properties set to the date-picker and imperatively handle internal changes.
555564
* This is done to avoid setting up additional $watches.
556565
*/
557566
DatePickerCtrl.prototype.installPropertyInterceptors = function() {
@@ -822,12 +831,12 @@
822831
// Attach click listener inside of a timeout because, if this open call was triggered by a
823832
// click, we don't want it to be immediately propagated up to the body and handled.
824833
var self = this;
825-
this.$timeout(function() {
834+
this.$mdUtil.nextTick(function() {
826835
// Use 'touchstart` in addition to click in order to work on iOS Safari, where click
827836
// events aren't propagated under most circumstances.
828837
// See http://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
829838
self.documentElement.on('click touchstart', self.bodyClickHandler);
830-
}, 100);
839+
}, false);
831840

832841
window.addEventListener(this.windowEventName, this.windowEventHandler);
833842
}

0 commit comments

Comments
 (0)