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

p-menubar: ERROR TypeError: Cannot read properties of undefined (reading 'item') when clicking on disabled menu item #14434

Closed
apolishko opened this issue Dec 26, 2023 · 3 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@apolishko
Copy link

Describe the bug

Create p-menubar where [model] is an array of MenuItems with all items disabled. Click on any disabled item. The following exception is thrown:

core.mjs:11760 ERROR TypeError: Cannot read properties of undefined (reading 'item')
at Menubar.onMenuFocus (primeng-menubar.mjs:777:184)
at Menubar_Template_p_menubarSub_menuFocus_3_listener (primeng-menubar.mjs:1114:30)
at executeListenerWithErrorHandling (core.mjs:24632:16)
at Object.wrapListenerIn_markDirtyAndPreventDefault [as next] (core.mjs:24665:22)
at ConsumerObserver.next (Subscriber.js:91:33)
at SafeSubscriber.next (Subscriber.js:60:26)
at SafeSubscriber.next (Subscriber.js:31:18)
at Subject.js:34:30
at errorContext (errorContext.js:19:9)
at EventEmitter
.next (Subject.js:27:21)

class Menubar {
    onMenuFocus(event: any) {
        this.focused = true;
        const processedItem = this.findVisibleItem(this.findFirstFocusedItemIndex());
        const focusedItemInfo = this.focusedItemInfo().index !== -1 ? this.focusedItemInfo() : { index: this.findFirstFocusedItemIndex(), level: 0, parentKey: '', item: processedItem.item };

        this.focusedItemInfo.set(focusedItemInfo);
        this.onFocus.emit(event);
    }
}

The processedItem is udefined.

Environment

Window 11

Reproducer

No response

Angular version

17.0.8

PrimeNG version

17.2.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

20.9.0

Browser(s)

Chrome 120.0.6099.129

Steps to reproduce the behavior

image

Expected behavior

There should be no exception

@apolishko apolishko added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 26, 2023
@abdallahmmu
Copy link

it will be helpful if you provide any stackblitz example to debug your problem

@apolishko
Copy link
Author

apolishko commented Dec 27, 2023

https://stackblitz.com/edit/stackblitz-starters-swwf8t?file=src%2Fmain.ts

Please click on any menu bar item and look at the console

@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 27, 2023
@cetincakiroglu cetincakiroglu self-assigned this Dec 27, 2023
@cetincakiroglu cetincakiroglu added this to the 17.3.0 milestone Dec 27, 2023
@cetincakiroglu
Copy link
Contributor

Thanks a lot for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

3 participants