Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
refactor(datepicker): move popup document click bind
Browse files Browse the repository at this point in the history
Moved the datepicker popup document click bind to
a timeout so having preventDefault and stopPropagation
on the element click event triggering the
popup to be open is no longer necessary.

Closes #3972
Fixes #3705
  • Loading branch information
RobJacobs authored and wesleycho committed Jul 29, 2015
1 parent fe0d954 commit 9f593ba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,9 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top = scope.position.top + element.prop('offsetHeight');

$document.bind('click', documentClickBind);

$timeout(function() {
scope.$broadcast('datepicker.focus');
$document.bind('click', documentClickBind);
}, 0, false);
} else {
$document.unbind('click', documentClickBind);
Expand Down
3 changes: 0 additions & 3 deletions src/datepicker/docs/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($
$scope.toggleMin();

$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();

$scope.opened = true;
};

Expand Down
6 changes: 4 additions & 2 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ describe('datepicker directive', function () {
});

describe('as popup', function () {
var inputEl, dropdownEl, $document, $sniffer;
var inputEl, dropdownEl, $document, $sniffer, $timeout;

function assignElements(wrapElement) {
inputEl = wrapElement.find('input');
Expand Down Expand Up @@ -1221,9 +1221,10 @@ describe('datepicker directive', function () {
describe('initially opened', function () {
var wrapElement;

beforeEach(inject(function(_$document_, _$sniffer_) {
beforeEach(inject(function(_$document_, _$sniffer_, _$timeout_) {
$document = _$document_;
$sniffer = _$sniffer_;
$timeout = _$timeout_;
$rootScope.isopen = true;
$rootScope.date = new Date('September 30, 2010 15:30:00');
wrapElement = $compile('<div><input ng-model="date" datepicker-popup is-open="isopen"><div>')($rootScope);
Expand Down Expand Up @@ -1295,6 +1296,7 @@ describe('datepicker directive', function () {
it('closes when click outside of calendar', function() {
expect(dropdownEl.length).toBe(1);

$timeout.flush(0);
$document.find('body').click();
assignElements(wrapElement);
expect(dropdownEl.length).toBe(0);
Expand Down

0 comments on commit 9f593ba

Please sign in to comment.