Skip to content

Commit

Permalink
button.js: Fix keyboard navigation
Browse files Browse the repository at this point in the history
This PR fixes the keyboard navigation again while still keeping #16223 fixed.

Closes #19192
  • Loading branch information
fdaugan authored and cvrebert committed Feb 16, 2016
1 parent ad5e656 commit ad1e98d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@

$(document)
.on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
var $btn = $(e.target).closest('.btn')
Plugin.call($btn, 'toggle')
if (!($(e.target).is('input[type="radio"]') || $(e.target).is('input[type="checkbox"]'))) e.preventDefault()
if (!($(e.target).is('input[type="radio"]') || $(e.target).is('input[type="checkbox"]'))) {
// Prevent double click on radios, and the double selections (so cancellation) on checkboxes
e.preventDefault()
// The target component still receive the focus
if ($btn.is('input,button')) $btn.trigger('focus')
else $btn.find('input:visible,button:visible').first().trigger('focus')
}
})
.on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
$(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
Expand Down
2 changes: 2 additions & 0 deletions js/tests/visual/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<h1>Button <small>Bootstrap Visual Test</small></h1>
</div>

<p>Try interacting via mouse, via keyboard, and via keyboard after first interacting via mouse. (Refresh the page between each trial.)</p>

<button type="button" data-loading-text="Loading for 3 seconds..." class="btn btn-primary js-loading-button">
Loading state
</button>
Expand Down

0 comments on commit ad1e98d

Please sign in to comment.