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

Component: Menu component throws a JS exception #13568

Closed
jacobvernau-soda opened this issue Aug 29, 2023 · 2 comments · Fixed by #13585
Closed

Component: Menu component throws a JS exception #13568

jacobvernau-soda opened this issue Aug 29, 2023 · 2 comments · Fixed by #13585
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@jacobvernau-soda
Copy link

jacobvernau-soda commented Aug 29, 2023

Describe the bug

When all menu items in a p-menu are disabled, the following TypeError appears when any part of the document is clicked.

error_handler.ts:45 ERROR TypeError: Cannot read properties of undefined (reading 'getAttribute')
    at Menu.changeFocusedOptionIndex (menu.ts:611:64)
    at Menu.onListBlur (menu.ts:503:14)
    at menu.ts:661:26
    at HTMLDocument.<anonymous> (dom_renderer.ts:317:11)
    at _ZoneDelegate.invokeTask (zone.js:402:31)
    at async-stack-tagging.ts:44:49
    at AsyncStackTaggingZoneSpec.onInvokeTask (async-stack-tagging.ts:44:30)
    at _ZoneDelegate.invokeTask (zone.js:401:60)
    at Object.onInvokeTask (ng_zone.ts:424:29)
    at _ZoneDelegate.invokeTask (zone.js:401:60)

Environment

Mac

Reproducer

https://stackblitz.com/edit/b8r8nz?file=src%2Fapp%2Fdemo%2Fmenu-basic-demo.ts

Angular version

16.2.1

PrimeNG version

16.0.2

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.1.3

Browser(s)

No response

Steps to reproduce the behavior

  1. Disable all menu items in a p-menu element
  2. Open dev console
  3. Click anywhere on document
  4. See TypeError

Expected behavior

All menu items should be able to be disabled without issue

@jacobvernau-soda jacobvernau-soda added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Aug 29, 2023
@dalenguyen
Copy link
Contributor

I think it happens when this function is triggered changeFocusedOptionIndex.

const links = DomHandler.find(this.containerViewChild.nativeElement, 'li[data-pc-section="menuitem"][data-p-disabled="false"]');

// when all menu is disabled. The list is an empty array, and the order has the value of 0.

order > -1 && this.focusedOptionIndex.set(links[order].getAttribute('id'));

It finds the list of menu items and changes the focus. However, the menu list is 0 since all of them are disabled.

I can help to create a PR for this.

@jacver
Copy link
Contributor

jacver commented Aug 30, 2023

PR for it here: #13585

@mertsincan mertsincan 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 Sep 2, 2023
@mertsincan mertsincan added this to the 16.3.2 milestone Sep 2, 2023
@mertsincan mertsincan changed the title Component: Menu Component: Menu component throws a JS exception Sep 2, 2023
@mertsincan mertsincan linked a pull request Sep 2, 2023 that will close this issue
mertsincan pushed a commit that referenced this issue Sep 2, 2023
* conditional for entirely disabled lists

* remove c.log
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

Successfully merging a pull request may close this issue.

4 participants