Commit f9cd88e0 authored by Patrick H. Lauke's avatar Patrick H. Lauke
Browse files

Fix radio and checkbox keyboard handling

Fix for problem that emerged from #16226 (`.active` class not actually
being applied) and expansion of the script to also correctly handle
keyboard interaction with checkboxes in `data-toggle="button"` groups
parent 45c798a4
Showing with 9 additions and 5 deletions
+9 -5
......@@ -57,14 +57,18 @@
var $input = this.$element.find('input')
if ($input.prop('type') == 'radio') {
if ($input.prop('checked')) changed = false
if (!$input.prop('checked') || !this.$element.hasClass('active')) $parent.find('.active').removeClass('active')
$parent.find('.active').removeClass('active')
this.$element.addClass('active')
} else if ($input.prop('type') == 'checkbox') {
if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false
this.$element.toggleClass('active')
}
if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
$input.prop('checked', this.$element.hasClass('active'))
if (changed) $input.trigger('change')
} else {
this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
this.$element.toggleClass('active')
}
if (changed) this.$element.toggleClass('active')
}
......@@ -107,7 +111,7 @@
var $btn = $(e.target)
if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
Plugin.call($btn, 'toggle')
if (!$(e.target).is('input[type="radio"]')) e.preventDefault()
if (!($(e.target).is('input[type="radio"]') || $(e.target).is('input[type="checkbox"]'))) e.preventDefault()
})
.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))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment