Skip to content

Commit

Permalink
Escape key should only close Dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Oct 3, 2014
1 parent 64a74e9 commit e5fc22c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}

Dropdown.prototype.keydown = function (e) {
if (!/(38|40|27)/.test(e.keyCode)) return
if (!/(38|40|27|32)/.test(e.which)) return

var $this = $(this)

Expand All @@ -67,7 +67,7 @@
var $parent = getParent($this)
var isActive = $parent.hasClass('open')

if (!isActive || (isActive && e.keyCode == 27)) {
if ((!isActive && e.which != 27) || (isActive && e.which == 27)) {
if (e.which == 27) $parent.find(toggle).trigger('focus')
return $this.trigger('click')
}
Expand All @@ -79,8 +79,8 @@

var index = $items.index($items.filter(':focus'))

if (e.keyCode == 38 && index > 0) index-- // up
if (e.keyCode == 40 && index < $items.length - 1) index++ // down
if (e.which == 38 && index > 0) index-- // up
if (e.which == 40 && index < $items.length - 1) index++ // down
if (!~index) index = 0

$items.eq(index).trigger('focus')
Expand Down

0 comments on commit e5fc22c

Please sign in to comment.