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

Bug/menu item missing aria labels #3417

Merged
merged 11 commits into from
Jul 18, 2023
11 changes: 10 additions & 1 deletion packages/menu/src/MenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ export class MenuItem extends LikeAnchor(Focusable) {
const assignedElements = event.target.assignedElements({
flatten: true,
});
this.hasSubmenu = this.open || !!assignedElements.length;
this.hasSubmenu = this.open || !!assignedElements;
if (this.hasSubmenu) {
this.setAttribute('aria-haspopup', 'true');
}
}

private handleRemoveActive(event: Event): void {
Expand Down Expand Up @@ -415,6 +418,7 @@ export class MenuItem extends LikeAnchor(Focusable) {
}
this.open = true;
this.active = true;
this.setAttribute('aria-expanded', 'true');
const submenu = (
this.shadowRoot.querySelector(
'slot[name="submenu"]'
Expand All @@ -425,6 +429,10 @@ export class MenuItem extends LikeAnchor(Focusable) {
this.handleSubmenuPointerenter
);
submenu.addEventListener('change', this.handleSubmenuChange);
if (!submenu.id) {
submenu.setAttribute('id', `${this.id}-submenu`);
}
this.setAttribute('aria-controls', submenu.id);
const popover = document.createElement('sp-popover');
const returnSubmenu = reparentChildren([submenu], popover, {
position: 'beforeend',
Expand All @@ -446,6 +454,7 @@ export class MenuItem extends LikeAnchor(Focusable) {
root: this.menuData.focusRoot,
});
const closeSubmenu = async (): Promise<void> => {
this.setAttribute('aria-expanded', 'false');
delete this.closeOverlay;
(await closeOverlay)();
};
Expand Down