Skip to content

Commit 36dd04f

Browse files
bekosbenjaminch
authored andcommitted
fix(dropdown): unbind toggle element event on scope destroy
Also, change the way disabled dropdownToggle is read from `attrs` instead of element property. Closes angular-ui#1867 Closes angular-ui#1870 Add an optionnal parameter on timepicker object in order to control the visibility of the controls arrows. chore(tests): Add unit tests for arrows control visibility Fixing demo semi colon issue. chore(release): Add unit tests chore(timepicker): Add LOC to check the user's input chore(timepicker): Remove method for showArrowControls option chore(timepicker): Remove Show / Hide option from demo chore(timepicker): Hides <tr> element rather than <td> element. chore(tests): Simplify arrows control visibility tests chore(tests): Refactoring arrow visibility tests fix(dropdown): unbind toggle element event on scope destroy Also, change the way disabled dropdownToggle is read from `attrs` instead of element property. Closes angular-ui#1867 Closes angular-ui#1870 Add an optionnal parameter on timepicker object in order to control the visibility of the controls arrows. chore(tests): Add unit tests for arrows control visibility Fixing demo semi colon issue. chore(release): Add unit tests chore(timepicker): Add LOC to check the user's input chore(timepicker): Remove method for showArrowControls option chore(timepicker): Remove Show / Hide option from demo chore(timepicker): Hides <tr> element rather than <td> element. chore(tests): Simplify arrows control visibility tests chore(tests): Refactoring arrow visibility tests refactor(rating): use `track by` in template Closes angular-ui#1724 refactor(pagination): add `href` and `track by` in templates Closes angular-ui#1725 fix(progressbar): allow fractional values for bar width * Fractions are limited to two decimals, and are not included in aria values. Closes angular-ui#1761 fix(dropdown): use $animate for adding and removing classes Closes angular-ui#1644 feat(datepicker): add `datepicker-mode`, `init-date` & today hint * Add two-way binded `datepicker-mode`. * Add optional `init-date` when no model value is specified. * Add hint for current date. * Use isolated scope for popup directive. * Use optional binding for `isOpen`. * Split each mode into it's own directive. Closes angular-ui#1599 BREAKING CHANGE: `show-weeks` is no longer a watched attribute `*-format` attributes have been renamed to `format-*` `min` attribute has been renamed to `min-date` `max` attribute has been renamed to `max-date` refactor(rating): evaluate attributes inside init function Closes angular-ui#1590 Closes angular-ui#1768 refactor(pagination): remove unused watch Closes angular-ui#1769 fix(typeahead): correctly higlight numeric matches Fixes angular-ui#1777 refactor(typeahead): use `ng-if` and `track by` in template Closes angular-ui#1722 demo(typeahead): correct demo for asyn results Fixes angular-ui#1740 refactor(datepicker): track buttons by date instead of $index refactor(pagination): move boundary & directions to the template Closes angular-ui#795 Closes angular-ui#1770 feat(alert): add WAI-ARIA markup Closes angular-ui#1806 chore(demo): fix fork button width Closes angular-ui#1805 fix(datepicker): `Today` button should not set time Fixes angular-ui#1726 Closes angular-ui#1808 fix(progressbar): number filter in bar template and only for percent Closes angular-ui#1807 refactor(dropdown): remove isolated scope Closes angular-ui#1818 feat(typeahead): add WAI-ARIA markup Closes angular-ui#1814 refactor(accordion): transclude function in compile is deprecated. Closes angular-ui#1789 refactor(carousel): use `track by` in template Closes angular-ui#1723 fix(datepicker): mark input field as invalid if the date is invalid Closes angular-ui#1845 Conflicts: src/datepicker/datepicker.js src/datepicker/test/datepicker.spec.js
1 parent 93da30d commit 36dd04f

File tree

9 files changed

+102
-7
lines changed

9 files changed

+102
-7
lines changed

Diff for: src/datepicker/datepicker.js

+12
Original file line numberDiff line numberDiff line change
@@ -320,18 +320,30 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
320320
var dateFormat,
321321
closeOnDateSelection = angular.isDefined(attrs.closeOnDateSelection) ? scope.$parent.$eval(attrs.closeOnDateSelection) : datepickerPopupConfig.closeOnDateSelection,
322322
appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? scope.$parent.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody;
323+
<<<<<<< HEAD
324+
=======
323325

324326
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;
325327

326328
scope.getText = function( key ) {
327329
return scope[key + 'Text'] || datepickerPopupConfig[key + 'Text'];
328330
};
331+
>>>>>>> 76acfef... refactor(rating): use `track by` in template
332+
333+
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;
334+
335+
<<<<<<< HEAD
336+
scope.getText = function( key ) {
337+
return scope[key + 'Text'] || datepickerPopupConfig[key + 'Text'];
338+
};
329339

330340
attrs.$observe('datepickerPopup', function(value) {
331341
dateFormat = value || datepickerPopupConfig.datepickerPopup;
332342
ngModel.$render();
333343
});
334344

345+
=======
346+
>>>>>>> 76acfef... refactor(rating): use `track by` in template
335347
// popup element used to display calendar
336348
var popupEl = angular.element('<div datepicker-popup-wrap><div datepicker></div></div>');
337349
popupEl.attr({

Diff for: src/datepicker/test/datepicker.spec.js

+3
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ describe('datepicker directive', function () {
795795

796796
});
797797

798+
<<<<<<< HEAD
798799
describe('setting datepickerPopupConfig', function() {
799800
var originalConfig = {};
800801
beforeEach(inject(function(datepickerPopupConfig) {
@@ -815,6 +816,8 @@ describe('datepicker directive', function () {
815816

816817
});
817818

819+
=======
820+
>>>>>>> 76acfef... refactor(rating): use `track by` in template
818821
describe('as popup', function () {
819822
var inputEl, dropdownEl, changeInputValueTo, $document;
820823

Diff for: src/dropdown/docs/demo.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<!-- Single button -->
1616
<div class="btn-group" dropdown is-open="status.isopen">
17-
<button type="button" class="btn btn-primary dropdown-toggle">
17+
<button type="button" class="btn btn-primary dropdown-toggle" ng-disabled="disabled">
1818
Button dropdown <span class="caret"></span>
1919
</button>
2020
<ul class="dropdown-menu" role="menu">
@@ -45,6 +45,7 @@
4545
<hr />
4646
<p>
4747
<button type="button" class="btn btn-default btn-sm" ng-click="toggleDropdown($event)">Toggle button dropdown</button>
48+
<button type="button" class="btn btn-warning btn-sm" ng-click="disabled = !disabled">Enable/Disable</button>
4849
</p>
4950

5051
</div>

Diff for: src/dropdown/dropdown.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,28 @@ angular.module('ui.bootstrap.dropdown', [])
112112
return;
113113
}
114114

115-
element.bind('click', function(event) {
115+
var toggleDropdown = function(event) {
116116
event.preventDefault();
117117
event.stopPropagation();
118118

119-
if ( !element.hasClass('disabled') && !element.prop('disabled') ) {
119+
if ( !element.hasClass('disabled') && !attrs.disabled ) {
120120
scope.$apply(function() {
121121
dropdownCtrl.toggle();
122122
});
123123
}
124-
});
124+
};
125+
126+
element.bind('click', toggleDropdown);
125127

126128
// WAI-ARIA
127129
element.attr({ 'aria-haspopup': true, 'aria-expanded': false });
128130
scope.$watch(dropdownCtrl.isOpen, function( isOpen ) {
129131
element.attr('aria-expanded', !!isOpen);
130132
});
133+
134+
scope.$on('$destroy', function() {
135+
element.unbind('click', toggleDropdown);
136+
});
131137
}
132138
};
133139
});

Diff for: src/dropdown/test/dropdown.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,35 @@ describe('dropdownToggle', function() {
9191
expect(elm.hasClass('open')).toBe(false);
9292
});
9393

94+
it('should not toggle if the element has `ng-disabled` as true', function() {
95+
$rootScope.isdisabled = true;
96+
var elm = $compile('<li class="dropdown"><div ng-disabled="isdisabled" dropdown-toggle></div><ul><li>Hello</li></ul></li>')($rootScope);
97+
$rootScope.$digest();
98+
elm.find('div').click();
99+
expect(elm.hasClass('open')).toBe(false);
100+
101+
$rootScope.isdisabled = false;
102+
$rootScope.$digest();
103+
elm.find('div').click();
104+
expect(elm.hasClass('open')).toBe(true);
105+
});
106+
107+
it('should unbind events on scope destroy', function() {
108+
var $scope = $rootScope.$new();
109+
var elm = $compile('<li class="dropdown"><button ng-disabled="isdisabled" dropdown-toggle></button><ul><li>Hello</li></ul></li>')($scope);
110+
$scope.$digest();
111+
112+
var buttonEl = elm.find('button');
113+
buttonEl.click();
114+
expect(elm.hasClass('open')).toBe(true);
115+
buttonEl.click();
116+
expect(elm.hasClass('open')).toBe(false);
117+
118+
$scope.$destroy();
119+
buttonEl.click();
120+
expect(elm.hasClass('open')).toBe(false);
121+
});
122+
94123
// issue 270
95124
it('executes other document click events normally', function() {
96125
var checkboxEl = $compile('<input type="checkbox" ng-click="clicked = true" />')($rootScope);

Diff for: src/timepicker/docs/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ All settings can be provided as attributes in the `<timepicker>` or globally con
3131
* `mousewheel`
3232
_(Defaults: true)_ :
3333
Whether user can scroll inside the hours & minutes input to increase or decrease it's values.
34+
35+
* `showArrowControls`
36+
_(Defaults: true)_ :
37+
Whether to show or hide the up and down control arrows.

Diff for: src/timepicker/test/timepicker.spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ describe('timepicker directive', function () {
376376
expect(getModelState()).toEqual([14, 40]);
377377
});
378378

379+
it('displays arrows controls by default correctly', function () {
380+
$rootScope.$digest();
381+
expect(element.find('tr').length).toBe(3);
382+
});
383+
379384
describe('attributes', function () {
380385
beforeEach(function() {
381386
$rootScope.hstep = 2;
@@ -874,5 +879,36 @@ describe('timepicker directive', function () {
874879
});
875880
});
876881

882+
describe('setting timepickerConfig arrow controls check initial show', function () {
883+
884+
beforeEach(inject(function(_$compile_, _$rootScope_) {
885+
$rootScope.showArrowsControls = true;
886+
element = $compile('<timepicker ng-model="time" ng-required="true" show-arrows-controls="showArrowsControls"></timepicker>')($rootScope);
887+
$rootScope.$digest();
888+
}));
889+
890+
it('displays arrows controls correctly', function () {
891+
$rootScope.$digest();
892+
expect(element.find('tr').length).toBe(3);
893+
});
894+
895+
});
896+
897+
describe('setting timepickerConfig arrow controls check initial hide', function () {
898+
899+
beforeEach(inject(function(_$compile_, _$rootScope_) {
900+
$rootScope.showArrowsControls = false;
901+
element = $compile('<timepicker ng-model="time" ng-required="true" show-arrows-controls="showArrowsControls"></timepicker>')($rootScope);
902+
$rootScope.$digest();
903+
}));
904+
905+
it('hides arrows controls correctly', function () {
906+
$rootScope.$digest();
907+
expect(element.find('tr').length).toBe(1);
908+
});
909+
910+
});
911+
877912
});
878913

914+

Diff for: src/timepicker/timepicker.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ angular.module('ui.bootstrap.timepicker', [])
66
showMeridian: true,
77
meridians: null,
88
readonlyInput: false,
9-
mousewheel: true
9+
mousewheel: true,
10+
showArrowsControls: true,
1011
})
1112

1213
.controller('TimepickerController', ['$scope', '$attrs', '$parse', '$log', '$locale', 'timepickerConfig', function($scope, $attrs, $parse, $log, $locale, timepickerConfig) {
@@ -63,6 +64,9 @@ angular.module('ui.bootstrap.timepicker', [])
6364
});
6465
}
6566

67+
// Show / Hide arrows control
68+
$scope.showArrowsControls = angular.isDefined($attrs.showArrowsControls) ? $scope.$parent.$eval($attrs.showArrowsControls) : timepickerConfig.showArrowsControls;
69+
6670
// Get $scope.hours in 24H mode if valid
6771
function getHoursFromTemplate ( ) {
6872
var hours = parseInt( $scope.hours, 10 );

Diff for: template/timepicker/timepicker.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<table>
22
<tbody>
3-
<tr class="text-center">
3+
<tr class="text-center" ng-if="showArrowsControls">
44
<td><a ng-click="incrementHours()" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
55
<td>&nbsp;</td>
66
<td><a ng-click="incrementMinutes()" class="btn btn-link"><span class="glyphicon glyphicon-chevron-up"></span></a></td>
@@ -16,7 +16,7 @@
1616
</td>
1717
<td ng-show="showMeridian"><button type="button" class="btn btn-default text-center" ng-click="toggleMeridian()">{{meridian}}</button></td>
1818
</tr>
19-
<tr class="text-center">
19+
<tr class="text-center" ng-if="showArrowsControls">
2020
<td><a ng-click="decrementHours()" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>
2121
<td>&nbsp;</td>
2222
<td><a ng-click="decrementMinutes()" class="btn btn-link"><span class="glyphicon glyphicon-chevron-down"></span></a></td>

0 commit comments

Comments
 (0)