Skip to content

Commit b33241a

Browse files
committed
Adds tabindex to select element and adds event handlers for focus and tab away
1 parent 4daa13e commit b33241a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

angular-dropdowns.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
dd.run(['$templateCache', function ($templateCache) {
1010
$templateCache.put('ngDropdowns/templates/dropdownSelect.html', [
11-
'<div ng-class="{\'disabled\': dropdownDisabled}" class="wrap-dd-select">',
11+
'<div ng-class="{\'disabled\': dropdownDisabled}" class="wrap-dd-select" tabindex="0">',
1212
'<span class="selected">{{dropdownModel[labelField]}}</span>',
1313
'<ul class="dropdown">',
1414
'<li ng-repeat="item in dropdownSelect"',
@@ -94,6 +94,13 @@
9494
}
9595
});
9696

97+
$element.bind('focus', function (event) {
98+
event.stopPropagation();
99+
if (!$scope.dropdownDisabled) {
100+
DropdownService.toggleActive($element);
101+
}
102+
});
103+
97104
$scope.$on('$destroy', function () {
98105
DropdownService.unregister($element);
99106
});
@@ -218,6 +225,15 @@
218225
});
219226
});
220227

228+
body.keydown(function(e) {
229+
var code = e.keyCode || e.which;
230+
if (code == '9') {
231+
angular.forEach(_dropdowns, function (el) {
232+
el.removeClass('active');
233+
});
234+
}
235+
});
236+
221237
service.register = function (ddEl) {
222238
_dropdowns.push(ddEl);
223239
};

0 commit comments

Comments
 (0)