Skip to content

Commit

Permalink
[popover2] a11y(MenuItem2): fix role structure when hasSubmenu (#5934)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvandercar-vt authored Feb 13, 2023
1 parent c54d5ac commit 1340704
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/popover2/src/menuItem2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ export class MenuItem2 extends AbstractPureComponent2<MenuItem2Props & React.Anc
const target = React.createElement(
tagName,
{
role: targetRole,
tabIndex: 0,
// if hasSubmenu, must apply correct role and tabIndex to the outer Popover2 target <span> instead of this target element
role: hasSubmenu ? "none" : targetRole,
tabIndex: hasSubmenu ? -1 : 0,
...removeNonHTMLProps(htmlProps),
...(disabled ? DISABLED_PROPS : {}),
className: anchorClasses,
Expand All @@ -283,7 +284,7 @@ export class MenuItem2 extends AbstractPureComponent2<MenuItem2Props & React.Anc
const liClasses = classNames({ [CoreClasses.MENU_SUBMENU]: hasSubmenu });
return (
<li className={liClasses} ref={elementRef} role={liRole} aria-selected={ariaSelected}>
{this.maybeRenderPopover(target, children)}
{this.maybeRenderPopover(target, { role: targetRole, tabIndex: 0 }, children)}
</li>
);
}
Expand All @@ -301,7 +302,11 @@ export class MenuItem2 extends AbstractPureComponent2<MenuItem2Props & React.Anc
);
}

private maybeRenderPopover(target: JSX.Element, children?: React.ReactNode) {
private maybeRenderPopover(
target: JSX.Element,
popoverTargetProps: Popover2Props["targetProps"],
children?: React.ReactNode,
) {
if (children == null) {
return target;
}
Expand All @@ -315,6 +320,7 @@ export class MenuItem2 extends AbstractPureComponent2<MenuItem2Props & React.Anc
hoverCloseDelay={0}
interactionKind="hover"
modifiers={SUBMENU_POPOVER_MODIFIERS}
targetProps={popoverTargetProps}
placement="right-start"
usePortal={false}
{...popoverProps}
Expand Down

1 comment on commit 1340704

@adidahiya
Copy link
Contributor

Choose a reason for hiding this comment

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

[popover2] a11y(MenuItem2): fix role structure when hasSubmenu (#5934)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.