🌐 AI搜索 & 代理 主页
Skip to content

Commit f94b832

Browse files
author
Olena Horal-Koretska
committed
fix(b-dropdown): Sets correct aria-haspopup attribute for the toggle button
the `aria-haspopup` attribute on the toggle button is set based on the `role` property provided for the dropdown popup
1 parent 45635d1 commit f94b832

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/components/dropdown/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ Providing a unique `id` prop ensures ARIA compliance by automatically adding the
664664
`aria-*` attributes in the rendered markup.
665665

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

669670
When a menu item doesn't trigger navigation, it is recommended to use the `<b-dropdown-item-button>`
670671
sub-component (which is not announced as a link) instead of `<b-dropdown-item>` (which is presented

src/components/dropdown/dropdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
140140
$buttonChildren = [h('span', { class: ['sr-only'] }, [this.toggleText])]
141141
buttonContentDomProps = {}
142142
}
143+
const ariaHasPopupRoles = ['menu', 'listbox', 'tree', 'grid', 'dialog']
143144

144145
const $toggle = h(
145146
BButton,
@@ -151,7 +152,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
151152
...this.toggleAttrs,
152153
// Must have attributes
153154
id: this.safeId('_BV_toggle_'),
154-
'aria-haspopup': 'true',
155+
'aria-haspopup': ariaHasPopupRoles.includes(role) ? role : 'false',
155156
'aria-expanded': toString(visible)
156157
},
157158
props: {

0 commit comments

Comments
 (0)