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

Fix: 5930 add id to menubar top level prevents focus #5933

4 changes: 2 additions & 2 deletions components/lib/menubar/Menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export const Menubar = React.memo(

const onEnterKey = (event) => {
if (focusedItemInfo.index !== -1) {
const element = DomHandler.findSingle(rootMenuRef.current, `li[id="${`${focusedItemId}`}"]`);
const element = DomHandler.findSingle(rootMenuRef.current, `li[data-id="${`${focusedItemId}`}"]`);
const anchorElement = element && DomHandler.findSingle(element, 'a[data-pc-section="action"]');

anchorElement ? anchorElement.click() : element && element.click();
Expand Down Expand Up @@ -483,7 +483,7 @@ export const Menubar = React.memo(

const scrollInView = (index = -1) => {
const id = index !== -1 ? `${idState}_${index}` : focusedItemId;
const element = DomHandler.findSingle(rootMenuRef.current, `li[id="${id}"]`);
const element = DomHandler.findSingle(rootMenuRef.current, `li[data-id="${id}"]`);

if (element) {
element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start' });
Expand Down
20 changes: 11 additions & 9 deletions components/lib/menubar/MenubarSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export const MenubarSub = React.memo(
};

const getItemId = (processedItem) => {
if (processedItem.item && processedItem.item.id) {
return processedItem.item.id;
}
return processedItem.item?.id;
};

const getItemDataId = (processedItem) => {
return `${props.id}_${processedItem.key}`;
};

Expand All @@ -87,7 +87,7 @@ export const MenubarSub = React.memo(
};

const isItemFocused = (processedItem) => {
return props.focusedItemId === getItemId(processedItem);
return props.focusedItemId === getItemDataId(processedItem);
};

const isItemGroup = (processedItem) => {
Expand All @@ -106,8 +106,8 @@ export const MenubarSub = React.memo(
const key = props.id + '_separator_' + index;
const separatorProps = mergeProps(
{
id: key,
key,
'data-id': key,
className: cx('separator'),
role: 'separator'
},
Expand Down Expand Up @@ -150,7 +150,8 @@ export const MenubarSub = React.memo(
return null;
}

const key = getItemId(processedItem);
const id = getItemId(processedItem);
const dataId = getItemDataId(processedItem);
const active = isItemActive(processedItem);
const focused = isItemFocused(processedItem);
const disabled = isItemDisabled(processedItem) || false;
Expand Down Expand Up @@ -236,8 +237,9 @@ export const MenubarSub = React.memo(

const menuitemProps = mergeProps(
{
id: key,
key,
id,
key: id,
'data-id': dataId,
role: 'menuitem',
'aria-label': item.label,
'aria-disabled': disabled,
Expand Down Expand Up @@ -283,7 +285,7 @@ export const MenubarSub = React.memo(
onFocus: props.onFocus,
onBlur: props.onBlur,
onKeyDown: props.onKeyDown,
id: props.id,
'data-id': props.id,
tabIndex: tabIndex,
'aria-activedescendant': props.ariaActivedescendant,
style: props.style,
Expand Down
Loading