-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
MenuItem: Keyboard navigation breaks when using template
#7505
Labels
Component: Accessibility
Issue or pull request is related to WCAG or ARIA
Type: Bug
Issue contains a defect related to a specific component.
Comments
This comment was marked as outdated.
This comment was marked as outdated.
template
template
template
To make the import React, { useRef } from 'react';
import { Menu } from 'primereact/menu';
import { Toast } from 'primereact/toast';
export default function CommandDemo() {
const itemRenderer = (item, options) => {
return (
<div
className="p-menuitem-content"
tabIndex={0}
onKeyDown={(e) => {
if (e.key === 'Enter') {
console.log('clicked with enter');
}
}}
+ onClick={(e) => {
+ options.onClick(e);
+ }}
>
<a className="flex align-items-center p-menuitem-link">
<span className={item.icon} />
<span className="mx-2">{item.label}</span>
{item.badge && <Badge className="ml-auto" value={item.badge} />}
{item.shortcut && (
<span className="ml-auto border-1 surface-border border-round surface-100 text-xs p-1">
{item.shortcut}
</span>
)}
</a>
</div>
);
};
const toast = useRef(null);
let items = [
{
label: 'New',
icon: 'pi pi-plus',
command: () => {
toast.current.show({
severity: 'success',
summary: 'Success',
detail: 'File created',
life: 3000,
});
},
template: itemRenderer,
},
{
label: 'Search',
icon: 'pi pi-search',
command: () => {
toast.current.show({
severity: 'warn',
summary: 'Search Completed',
detail: 'No results found',
life: 3000,
});
},
template: itemRenderer,
},
];
return (
<>
<Menu model={items} />
<Toast ref={toast} />
</>
);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Component: Accessibility
Issue or pull request is related to WCAG or ARIA
Type: Bug
Issue contains a defect related to a specific component.
Describe the bug
I was facing a problem with MenuItem command not getting triggered by hitting the enter key when providing a template
But if I pass anything other than template it works
Reproducer
https://stackblitz.com/edit/xp3desv1-kjtkjrvh?file=src%2FApp.jsx
System Information
Steps to reproduce the behavior
Expected behavior
search menuitem should work when hitting the enter key
The text was updated successfully, but these errors were encountered: