Skip to content
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
12 changes: 7 additions & 5 deletions packages/react-core/src/components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
}
}, [flyoutVisible, flyoutTarget]);

const handleFlyout = (event: React.KeyboardEvent) => {
const key = event.key;
const handleFlyout = (event: React.KeyboardEvent | React.MouseEvent) => {
const key = (event as React.KeyboardEvent).key;
const target = event.target;
const type = event.type;

if (key === ' ' || key === 'Enter' || key === 'ArrowRight') {
if (key === ' ' || key === 'Enter' || key === 'ArrowRight' || type === 'click') {
event.stopPropagation();
if (!flyoutVisible) {
showFlyout(true);
Expand Down Expand Up @@ -248,7 +249,7 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
if (isOnPath) {
additionalProps['aria-expanded'] = true;
} else if (hasFlyout) {
additionalProps['aria-haspopup'] = true;
additionalProps['aria-haspopup'] = 'menu';
additionalProps['aria-expanded'] = flyoutVisible;
}
const getAriaCurrent = () => {
Expand Down Expand Up @@ -305,12 +306,13 @@ const MenuItemBase: React.FunctionComponent<MenuItemProps> = ({
className={css(styles.menuItem, getIsSelected() && !hasCheck && styles.modifiers.selected, className)}
aria-current={getAriaCurrent()}
{...(!hasCheck && { disabled: isDisabled })}
{...(!hasCheck && { role: 'menuitem' })}
{...(!hasCheck && !flyoutMenu && { role: 'menuitem' })}
ref={innerRef}
{...(!hasCheck && {
onClick: (event: any) => {
onItemSelect(event, onSelect);
_drill && _drill();
flyoutMenu && handleFlyout(event);
}
})}
{...(hasCheck && { htmlFor: randomId })}
Expand Down
6 changes: 6 additions & 0 deletions packages/react-core/src/components/Nav/NavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
</span>
);

const ariaFlyoutProps = {
'aria-haspopup': 'menu',
'aria-expanded': flyoutVisible
};

const renderDefaultLink = (context: any): React.ReactNode => {
const preventLinkDefault = preventDefault || !to;
return (
Expand All @@ -164,6 +169,7 @@ export const NavItem: React.FunctionComponent<NavItemProps> = ({
)}
aria-current={isActive ? 'page' : null}
tabIndex={isNavOpen ? null : '-1'}
{...(hasFlyout && { ...ariaFlyoutProps })}
{...props}
>
{children}
Expand Down