'
@@ -487,11 +487,27 @@ $(function () {
.on('shown.bs.dropdown', function () {
assert.ok(true, 'shown was fired')
- $input.trigger('focus').trigger($.Event('keydown', { which: 38 }))
- assert.ok($(document.activeElement).is($input), 'input still focused')
+ // Space key
+ $input.trigger('focus').trigger($.Event('keydown', { which: 32 }))
+ assert.ok($(document.activeElement)[0] === $input[0], 'input still focused')
+ $textarea.trigger('focus').trigger($.Event('keydown', { which: 32 }))
+ assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused')
+ // Key up
+ $input.trigger('focus').trigger($.Event('keydown', { which: 38 }))
+ assert.ok($(document.activeElement)[0] === $input[0], 'input still focused')
$textarea.trigger('focus').trigger($.Event('keydown', { which: 38 }))
- assert.ok($(document.activeElement).is($textarea), 'textarea still focused')
+ assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused')
+
+ // Key down
+ $input.trigger('focus').trigger($.Event('keydown', { which: 40 }))
+ assert.ok($(document.activeElement)[0] === $input[0], 'input still focused')
+ $textarea.trigger('focus').trigger($.Event('keydown', { which: 40 }))
+ assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused')
+
+ // Key escape
+ $input.trigger('focus').trigger($.Event('keydown', { which: 27 }))
+ assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown')
done()
})
@@ -499,6 +515,126 @@ $(function () {
$dropdown.trigger('click')
})
+ QUnit.test('should ignore space key events for
s within dropdown, and accept up, down and escape', function (assert) {
+ assert.expect(6)
+ var done = assert.async()
+
+ var dropdownHTML = '
'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+
+ var $input = $('#input')
+
+ $dropdown
+ .parent('.dropdown')
+ .one('shown.bs.dropdown', function () {
+ assert.ok(true, 'shown was fired')
+
+ // Key space
+ $input.trigger('focus').trigger($.Event('keydown', { which: 32 }))
+ assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
+ assert.ok($(document.activeElement).is($input), 'input is still focused')
+
+ // Key escape
+ $input.trigger('focus').trigger($.Event('keydown', { which: 27 }))
+ assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown')
+
+ $dropdown
+ .parent('.dropdown')
+ .one('shown.bs.dropdown', function () {
+
+ // Key down
+ $input.trigger('focus').trigger($.Event('keydown', { which: 40 }))
+ assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused')
+
+ $dropdown
+ .parent('.dropdown')
+ .one('shown.bs.dropdown', function () {
+
+ // Key up
+ $input.trigger('focus').trigger($.Event('keydown', { which: 38 }))
+ assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused')
+ done()
+ }).bootstrapDropdown('toggle')
+ $input.trigger('click')
+ })
+ $input.trigger('click')
+ })
+ $input.trigger('click')
+ })
+
+ QUnit.test('should ignore space key events for