Skip to content

Commit

Permalink
fix(b-button): add aria-disabled attribute when explicitly set
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hegman committed Jan 4, 2024
1 parent 5173dd1 commit 8106b61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/components/button/button.js
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
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

0 comments on commit 8106b61

Please sign in to comment.