0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00

Only change aria-pressed if it's not an input-based radio or checkbox group

* Only change aria-pressed if it's not an input-based radio or checkbox group

aria-pressed="true"/aria-pressed="false" is really only useful for
making on/off toggles out of, say, `<button>` elements. the attribute is
useless (and potentially confusing/conflicting) on, say, `<label>`
elements for an existing `<input type="radio">` or similar.

* Add unit test for buttons.js and radio/checkbox inputs in button groups
This commit is contained in:
Patrick H. Lauke 2017-04-10 14:43:54 +01:00 committed by GitHub
parent 278ddd0acd
commit 3f6e1faf45
2 changed files with 24 additions and 2 deletions

View File

@ -66,6 +66,7 @@ const Button = (($) => {
toggle() {
let triggerChangeEvent = true
let addAriaPressed = true
const rootElement = $(this._element).closest(
Selector.DATA_TOGGLE
)[0]
@ -94,12 +95,15 @@ const Button = (($) => {
}
input.focus()
addAriaPressed = false
}
}
this._element.setAttribute('aria-pressed',
!$(this._element).hasClass(ClassName.ACTIVE))
if (addAriaPressed) {
this._element.setAttribute('aria-pressed',
!$(this._element).hasClass(ClassName.ACTIVE))
}
if (triggerChangeEvent) {
$(this._element).toggleClass(ClassName.ACTIVE)

View File

@ -138,4 +138,22 @@ $(function () {
assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked')
})
QUnit.test('should not add aria-pressed on labels for radio/checkbox inputs in a data-toggle="buttons" group', function (assert) {
assert.expect(2)
var groupHTML = '<div class="btn-group" data-toggle="buttons">'
+ '<label class="btn btn-primary"><input type="checkbox" autocomplete="off"> Checkbox</label>'
+ '<label class="btn btn-primary"><input type="radio" name="options" autocomplete="off"> Radio</label>'
+ '</div>'
var $group = $(groupHTML).appendTo('#qunit-fixture')
var $btn1 = $group.children().eq(0)
var $btn2 = $group.children().eq(1)
$btn1.find('input').trigger('click')
assert.ok($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute')
$btn2.find('input').trigger('click')
assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute')
})
})