primefaces / primefaces/primereact
Menu auto-closes on MenuItem.template clicks even when interacting with custom content
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 8.3k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Title: Menu auto-closes on MenuItem.template clicks
Description:
When using a Menu with MenuItem.template, any click inside the template (e.g., a checkbox) closes the menu immediately. The menu should stay open while interacting with elements inside the template.
Minimal Reproducible Example:
import React, { useState, useRef } from "react";
import { Menu } from "primereact/menu";
import { Button } from "primereact/button";
import { Checkbox } from "primereact/checkbox";
export default function ColumnMenuExample() {
const menuRef = useRef<Menu>(null);
const [checked, setChecked] = useState(false);
const items = [
{
template: () => (
<div onClick={(e) => e.stopPropagation()}>
<Checkbox checked={checked} onChange={() => setChecked(!checked)} />
Column 1
</div>
),
},
];
return (
<div>
<Button label="Toggle Menu" onClick={(e) => menuRef.current?.toggle(e)} />
<Menu ref={menuRef} popup model={items} />
</div>
);
}
Steps to Reproduce:
- Click “Toggle Menu”.
- Click the checkbox inside the menu.
Actual behavior: Menu closes after checkbox click.
Expected behavior: Menu should stay open while interacting with template elements.
Workaround: Adding onClick={(e) => e.stopPropagation()} on the template prevents auto-close.
Environment:
"primereact": "^10.9.7",
"react": "19.2.1",
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Menu popup item click handling and reproduce the issue with the provided MenuItem.template and Checkbox example. Trace how clicks from template content are treated, then verify that interacting with template elements keeps the menu open while ordinary menu item behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100