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

Menubar: Does not respect the MenuItem id property #5827

Closed
XdertY opened this issue Jan 23, 2024 · 2 comments · Fixed by #5828
Closed

Menubar: Does not respect the MenuItem id property #5827

XdertY opened this issue Jan 23, 2024 · 2 comments · Fixed by #5828
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@XdertY
Copy link

XdertY commented Jan 23, 2024

The bug is pretty simple - when passing model to the Menubar component - if an menuItem has an id - the rendered ListItem (html li element) does not have that id. The latest version, in which this functionality was working, is 10.2.1. In the reproduction, that I have created in CodeSandbox, there is a MenuBar with 1 menuitem as model and a text which changes if there is an element in the DOM Tree with the given id. The example is uploaded with version 10.3.3. If you go to the package.json file and change the version to one before 10.3.0 , the text will change to "Element found" -> meaning that for previous versions the html li elements that get rendered by the Menubar component respect the given ids in the MenuItem array.

Reproducer

https://codesandbox.io/p/sandbox/primereact-test-forked-vcddkx?file=%2Fpackage.json%3A10%2C26

PrimeReact version

10.3.3, 10.3.2, 10.3.1, 10.3.0

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

All browsers

Expected behavior

If an Menuitem, passed to the Menubar component, as a model, has an id -> the rendered html li item for that MenuItem to have the defined id.

@XdertY XdertY added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jan 23, 2024
@XdertY
Copy link
Author

XdertY commented Jan 23, 2024

I went through the code of the Menubar component and it seems to me that in the MenubarSub.js file in the getItemId function there is a mistake:

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

It uses the props.id, which is the id passed to the whole Menubar component. Instead I think it should look something like this:

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

If there is a specific id passed to the processedItem (Menuitem) - it should be respected. Otherwise use the id of the element (if no id is provided to the Menubar component - it gets set to a unique one using the UniqueComponentId() function)

melloware added a commit to melloware/primereact that referenced this issue Jan 23, 2024
@melloware
Copy link
Member

@XdertY that put me in the right direction but i changed your logic a little bit.

@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jan 23, 2024
@melloware melloware added this to the 10.4.0 milestone Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants