From e283cea0e4e2cfb1637f3acc0c3488540fc96b5c Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Tue, 2 Feb 2016 19:57:54 -0800 Subject: [PATCH] fix(datepicker): stop event bubbling from buttons - Stop event bubbling from clicks in popup Closes #5400 Fixes #5347 BREAKING CHANGE: This requires $event to be passed in the second argument of the select function and in the close argument for the popup template --- src/datepicker/datepicker.js | 8 +++- src/datepicker/test/datepicker.spec.js | 51 ++++++++++++++++++++++++++ template/datepicker/popup.html | 10 ++--- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 49ad11d19c..41932d450b 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -939,7 +939,9 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi } }; - scope.select = function(date) { + scope.select = function(date, evt) { + evt.stopPropagation(); + if (date === 'today') { var today = new Date(); if (angular.isDate(scope.date)) { @@ -952,7 +954,9 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi scope.dateSelection(date); }; - scope.close = function() { + scope.close = function(evt) { + evt.stopPropagation(); + scope.isOpen = false; element[0].focus(); }; diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 7ec3ccedb3..a45ced1827 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1638,6 +1638,57 @@ describe('datepicker', function() { }); }); + describe('basic popup', function() { + var wrapElement, inputEl, dropdownEl; + + function assignElements(wrapElement) { + inputEl = wrapElement.find('input'); + dropdownEl = wrapElement.find('ul'); + element = dropdownEl.find('table'); + } + + beforeEach(function() { + $rootScope.date = new Date('September 30, 2010 15:30:00'); + $rootScope.isopen = true; + wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + }); + + it('should stop click event from bubbling from today button', function() { + var bubbled = false; + wrapElement.on('click', function() { + bubbled = true; + }); + + wrapElement.find('.uib-datepicker-current').trigger('click'); + + expect(bubbled).toBe(false); + }); + + it('should stop click event from bubbling from clear button', function() { + var bubbled = false; + wrapElement.on('click', function() { + bubbled = true; + }); + + wrapElement.find('.uib-clear').trigger('click'); + + expect(bubbled).toBe(false); + }); + + it('should stop click event from bubbling from close button', function() { + var bubbled = false; + wrapElement.on('click', function() { + bubbled = true; + }); + + wrapElement.find('.uib-close').trigger('click'); + + expect(bubbled).toBe(false); + }); + }); + describe('ngModelOptions allowInvalid', function() { var $sniffer, inputEl; diff --git a/template/datepicker/popup.html b/template/datepicker/popup.html index 0ac28a477f..d16854fdf9 100644 --- a/template/datepicker/popup.html +++ b/template/datepicker/popup.html @@ -2,11 +2,11 @@