0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-02 14:24:19 +01:00

Escape key should only close Dropdown

This commit is contained in:
fat 2014-10-02 20:43:03 -07:00
parent 64a74e9354
commit e5fc22ccfa

View File

@ -55,7 +55,7 @@
} }
Dropdown.prototype.keydown = function (e) { 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) var $this = $(this)
@ -67,7 +67,7 @@
var $parent = getParent($this) var $parent = getParent($this)
var isActive = $parent.hasClass('open') 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') if (e.which == 27) $parent.find(toggle).trigger('focus')
return $this.trigger('click') return $this.trigger('click')
} }
@ -79,8 +79,8 @@
var index = $items.index($items.filter(':focus')) var index = $items.index($items.filter(':focus'))
if (e.keyCode == 38 && index > 0) index-- // up if (e.which == 38 && index > 0) index-- // up
if (e.keyCode == 40 && index < $items.length - 1) index++ // down if (e.which == 40 && index < $items.length - 1) index++ // down
if (!~index) index = 0 if (!~index) index = 0
$items.eq(index).trigger('focus') $items.eq(index).trigger('focus')