Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit bb8f1dd

Browse files
committed
Avoid crash inside _ensureHighlightVisible() when ctrl.items is empty
1 parent fba8659 commit bb8f1dd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/select.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,21 +235,25 @@ angular.module('ui.select', [])
235235
// Bind to keyboard shortcuts
236236
// Cannot specify a namespace: not supported by jqLite
237237
_searchInput.on('keydown', function(e) {
238-
var key = e.which;
238+
// Keyboard shortcuts are all about the items,
239+
// does not make sense (and will crash) if ctrl.items is empty
240+
if (ctrl.items.length > 0) {
241+
var key = e.which;
242+
243+
$scope.$apply(function() {
244+
var processed = _onKeydown(key);
245+
if (processed) {
246+
e.preventDefault();
247+
e.stopPropagation();
248+
}
249+
});
239250

240-
$scope.$apply(function() {
241-
var processed = _onKeydown(key);
242-
if (processed) {
243-
e.preventDefault();
244-
e.stopPropagation();
251+
switch (key) {
252+
case Key.Down:
253+
case Key.Up:
254+
_ensureHighlightVisible();
255+
break;
245256
}
246-
});
247-
248-
switch (key) {
249-
case Key.Down:
250-
case Key.Up:
251-
_ensureHighlightVisible();
252-
break;
253257
}
254258
});
255259

0 commit comments

Comments
 (0)