primefaces / primefaces/primereact

Menu auto-closes on MenuItem.template clicks even when interacting with custom content

Open
#8,433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Needs Triage
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:

  1. Click “Toggle Menu”.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.