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
2 changes: 1 addition & 1 deletion packages/accordion/src/AccordionItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Adobe. All rights reserved.
Copyright. 2020 Adobe. All rights reserved.
blunteshwar marked this conversation as resolved.
Show resolved Hide resolved
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Expand Down
1 change: 1 addition & 0 deletions packages/menu/src/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ export class Menu extends SpectrumElement {
}
item.focused = this.hasVisibleFocusInTree();
this.setAttribute('aria-activedescendant', item.id);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this white space

if (
item.menuData.selectionRoot &&
item.menuData.selectionRoot !== this
Expand Down
11 changes: 11 additions & 0 deletions packages/menu/src/MenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ export class MenuItem extends LikeAnchor(Focusable) {
flatten: true,
});
this.hasSubmenu = this.open || !!assignedElements.length;
blunteshwar marked this conversation as resolved.
Show resolved Hide resolved
if (this.hasSubmenu) {
this.setAttribute('aria-haspopup', 'true');
}
}

private handleRemoveActive(event: Event): void {
Expand Down Expand Up @@ -415,6 +418,8 @@ 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,7 +430,10 @@ export class MenuItem extends LikeAnchor(Focusable) {
this.handleSubmenuPointerenter
);
submenu.addEventListener('change', this.handleSubmenuChange);
submenu.setAttribute('id', `${this.id}-submenu`);
blunteshwar marked this conversation as resolved.
Show resolved Hide resolved
this.setAttribute('aria-controls', submenu.id);
const popover = document.createElement('sp-popover');

const returnSubmenu = reparentChildren([submenu], popover, {
position: 'beforeend',
prepareCallback: (el) => {
Expand All @@ -440,12 +448,15 @@ export class MenuItem extends LikeAnchor(Focusable) {
};
},
});

const closeOverlay = openOverlay(this, 'click', popover, {
placement: this.isLTR ? 'right-start' : 'left-start',
receivesFocus: 'auto',

root: this.menuData.focusRoot,
});
const closeSubmenu = async (): Promise<void> => {
this.setAttribute('aria-expanded', 'false');
delete this.closeOverlay;
(await closeOverlay)();
};
Expand Down