Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions js/src/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Button = (($) => {

toggle() {
let triggerChangeEvent = true
let addAriaPressed = true
const rootElement = $(this._element).closest(
Selector.DATA_TOGGLE
)[0]
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions js/tests/unit/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

})