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

fix(b-button): add aria-disabled attribute when explicitly set #7190

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const computeAttrs = (props, data) => {
const nonStandardTag = isNonStandardTag(props)
const hashLink = link && props.href === '#'
const role = data.attrs && data.attrs.role ? data.attrs.role : null
const ariaDisabled =
data.attrs && data.attrs['aria-disabled'] ? data.attrs['aria-disabled'] : null
let tabindex = data.attrs ? data.attrs.tabindex : null
if (nonStandardTag || hashLink) {
tabindex = '0'
Expand All @@ -98,7 +100,7 @@ const computeAttrs = (props, data) => {
// Except when link has `href` of `#`
role: nonStandardTag || hashLink ? 'button' : role,
// We set the `aria-disabled` state for non-standard tags
'aria-disabled': nonStandardTag ? String(props.disabled) : null,
'aria-disabled': nonStandardTag ? String(props.disabled) : ariaDisabled,
// For toggles, we need to set the pressed state for ARIA
'aria-pressed': toggle ? String(props.pressed) : null,
// `autocomplete="off"` is needed in toggle mode to prevent some browsers
Expand Down
12 changes: 12 additions & 0 deletions src/components/button/button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ describe('button', () => {
wrapper.destroy()
})

it('button has aria-disabled attribute when explicitly set', () => {
const wrapper = mount(BButton, {
attrs: {
'aria-disabled': 'true'
}
})

expect(wrapper.attributes('aria-disabled')).toBe('true')

wrapper.destroy()
})

it('link has attribute aria-disabled when disabled set', async () => {
const wrapper = mount(BButton, {
propsData: {
Expand Down