Skip to content

Commit 02da84f

Browse files
committed
fix broken focus/click interaction, fixes #66
1 parent c4f8092 commit 02da84f

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

angular-dropdowns.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,22 @@
8585
$scope.dropdownOnchange({
8686
selected: selected
8787
});
88+
$element[0].blur(); //trigger blur to clear active
8889
};
8990

90-
var onEvent = function (event) {
91+
$element.bind('click', function (event) {
9192
event.stopPropagation();
93+
});
94+
95+
$element.bind('focus', function () {
9296
if (!$scope.dropdownDisabled) {
9397
DropdownService.toggleActive($element);
9498
}
95-
};
99+
});
96100

97-
$element.bind('click', onEvent);
98-
$element.bind('focus', onEvent);
101+
$element.bind('blur', function () {
102+
DropdownService.clearActive();
103+
});
99104

100105
$scope.$on('$destroy', function () {
101106
DropdownService.unregister($element);
@@ -170,14 +175,12 @@
170175
});
171176
};
172177

173-
var onEvent = function (event) {
178+
$element.bind('click', function (event) {
174179
event.stopPropagation();
175180
if (!$scope.dropdownDisabled) {
176181
DropdownService.toggleActive(tpl);
177182
}
178-
};
179-
180-
$element.bind('click', onEvent);
183+
});
181184

182185
$scope.$on('$destroy', function () {
183186
DropdownService.unregister(tpl);
@@ -223,16 +226,6 @@
223226
});
224227
});
225228

226-
body.bind('keydown', function (evt) {
227-
var code = evt.keyCode || evt.which;
228-
//on tab, remove 'active' any dropdown element
229-
if (code === 9) {
230-
angular.forEach(_dropdowns, function (el) {
231-
el.removeClass('active');
232-
});
233-
}
234-
});
235-
236229
service.register = function (ddEl) {
237230
_dropdowns.push(ddEl);
238231
};
@@ -255,6 +248,16 @@
255248
ddEl.toggleClass('active');
256249
};
257250

251+
service.clearActive = function () {
252+
angular.forEach(_dropdowns, function (el) {
253+
el.removeClass('active');
254+
});
255+
};
256+
257+
service.isActive = function (ddEl) {
258+
return ddEl.hasClass('active');
259+
};
260+
258261
return service;
259262
}
260263
]);

0 commit comments

Comments
 (0)