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

[Bug]: TypeError: Cannot read properties of undefined (reading 'selectionRoot') in Menu.handlePointerBasedSelection #4456

Open
1 task done
spdev3000 opened this issue May 15, 2024 · 3 comments
Labels
bug Something isn't working Component: Menu

Comments

@spdev3000
Copy link
Collaborator

Code of conduct

  • I agree to follow this project's code of conduct.

Impacted component(s)

Menu

Expected behavior

When using non-menu-item components as submenu clicking those components shouldn't trigger TypeError

Actual behavior

Using arbitrary components as submenu items and clicking them produces the TypeError:
Cannot read properties of undefined (reading 'selectionRoot') in Menu.handlePointerBasedSelection

Screenshots

Screenshot 2024-05-15 at 12 16 48

What browsers are you seeing the problem in?

No response

How can we reproduce this issue?

  1. Go to '...'
  2. Click on '....'
  3. Scroll to '....'
  4. Check console
  5. See error

Sample code that illustrates the problem

This might be fixed by adding ? after menuData, see:

 target?.menuData?.selectionRoot === this &&

in

target?.menuData.selectionRoot === this &&

Logs taken while reproducing problem

No response

@spdev3000 spdev3000 added bug Something isn't working Component: Menu triage An issue needing triage labels May 15, 2024
@Westbrook
Copy link
Contributor

I'm surprised that without a Menu Item that this code is finding a trigger. Can you share what the trigger is so we can understand how it is both el.getAttribute('role') === this.childRole and el.menuData === undefined?

@spdev3000
Copy link
Collaborator Author

  handlePointerBasedSelection(event) {
    const path = event.composedPath();
    const target = path.find((el) => {
      if (!(el instanceof Element)) {
        return false;
      }
      console.log("MENU SWC: ", el);
      return el.getAttribute("role") === this.childRole;
    });

prints out:

<li class="spectrum-Menu-item" tabindex="0" role="menuitem"><span class="spectrum-Menu-itemLabel"><span>Edit version info</span></span></li>

and leads to:

    TypeError: Cannot read properties of undefined (reading 'selectionRoot')
    at Menu.handlePointerBasedSelection (chunk-SCU35XXF.js?v=c2a8ef54:347:59)
    at Menu.handlePointerup (chunk-SCU35XXF.js?v=c2a8ef54:321:10)
    at Menu.nrWrapper (chunk-DTJESBZO.js?v=c2a8ef54:71:21)

@najikahalsema najikahalsema removed the triage An issue needing triage label May 22, 2024
@najikahalsema
Copy link
Collaborator

We can add this, but we should make sure we add tests for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Component: Menu
Projects
None yet
Development

No branches or pull requests

3 participants