Skip to content

fix(b-dropdown): Sets correct aria-haspopup attribute for the toggle button #6865

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

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
3 changes: 2 additions & 1 deletion src/components/dropdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ Providing a unique `id` prop ensures ARIA compliance by automatically adding the
`aria-*` attributes in the rendered markup.

The default ARIA role is set to `menu`, but you can change this default to another role (such as
`navigation`) via the `role` prop, depending on your user case.
`navigation`) via the `role` prop, depending on your user case. The `role` prop value will be used
to determine `aria-haspopup` attribute for the toggle button.

When a menu item doesn't trigger navigation, it is recommended to use the `<b-dropdown-item-button>`
sub-component (which is not announced as a link) instead of `<b-dropdown-item>` (which is presented
Expand Down
3 changes: 2 additions & 1 deletion src/components/dropdown/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
$buttonChildren = [h('span', { class: ['sr-only'] }, [this.toggleText])]
buttonContentDomProps = {}
}
const ariaHasPopupRoles = ['menu', 'listbox', 'tree', 'grid', 'dialog']

const $toggle = h(
BButton,
Expand All @@ -151,7 +152,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
...this.toggleAttrs,
// Must have attributes
id: this.safeId('_BV_toggle_'),
'aria-haspopup': 'true',
'aria-haspopup': ariaHasPopupRoles.includes(role) ? role : 'false',
'aria-expanded': toString(visible)
},
props: {
Expand Down
14 changes: 7 additions & 7 deletions src/components/dropdown/dropdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('dropdown', () => {
expect($button.classes()).toContain('dropdown-toggle')
expect($button.classes().length).toBe(3)
expect($button.attributes('aria-haspopup')).toBeDefined()
expect($button.attributes('aria-haspopup')).toEqual('true')
expect($button.attributes('aria-haspopup')).toEqual('menu')
expect($button.attributes('aria-expanded')).toBeDefined()
expect($button.attributes('aria-expanded')).toEqual('false')
expect($button.attributes('id')).toBeDefined()
Expand Down Expand Up @@ -125,7 +125,7 @@ describe('dropdown', () => {
expect($toggle.classes()).toContain('dropdown-toggle-split')
expect($toggle.classes().length).toBe(4)
expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('false')
expect($toggle.attributes('id')).toBeDefined()
Expand Down Expand Up @@ -551,7 +551,7 @@ describe('dropdown', () => {
expect($dropdown.vm).toBeDefined()

expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('false')
expect($dropdown.classes()).not.toContain('show')
Expand All @@ -564,7 +564,7 @@ describe('dropdown', () => {
await waitNT(wrapper.vm)

expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('true')
expect($dropdown.classes()).toContain('show')
Expand Down Expand Up @@ -754,7 +754,7 @@ describe('dropdown', () => {
const $dropdown = wrapper.find('.dropdown')

expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('false')
expect($dropdown.classes()).not.toContain('show')
Expand All @@ -765,7 +765,7 @@ describe('dropdown', () => {
expect(wrapper.emitted('show')).toBeDefined()
expect(wrapper.emitted('show').length).toBe(1)
expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('false')
expect($dropdown.classes()).not.toContain('show')
Expand All @@ -777,7 +777,7 @@ describe('dropdown', () => {
expect(wrapper.emitted('show')).toBeDefined()
expect(wrapper.emitted('show').length).toBe(2)
expect($toggle.attributes('aria-haspopup')).toBeDefined()
expect($toggle.attributes('aria-haspopup')).toEqual('true')
expect($toggle.attributes('aria-haspopup')).toEqual('menu')
expect($toggle.attributes('aria-expanded')).toBeDefined()
expect($toggle.attributes('aria-expanded')).toEqual('true')
expect($dropdown.classes()).toContain('show')
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy