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]: Menu component does not protect access to refs in focusItem #16395

Closed
2 tasks done
Kilian-Collender opened this issue May 9, 2024 · 2 comments · Fixed by #16466
Closed
2 tasks done

[Bug]: Menu component does not protect access to refs in focusItem #16395

Kilian-Collender opened this issue May 9, 2024 · 2 comments · Fixed by #16466
Labels
good first issue 👋 Used by GitHub to elevate contribution opportunities needs: community contribution Due to roadmap and resource availability, we are looking for outside contributions on this issue. severity: 2 User cannot complete task, and/or no workaround status: help wanted 👐 type: bug 🐛

Comments

@Kilian-Collender
Copy link
Contributor

Package

@carbon/react

Browser

Chrome

Package version

v1.49.0

React version

v18.2.0

Description

In the findIndex function here

item.ref.current.contains(document.activeElement)

It tries to use contains against the current ref value without checking that the ref value is not null.

During our automations this is throwing the following error Cannot read properties of null (reading 'contains') as item.ref.current is null .

This requires just a simple check to ensure that the value is not null before calling contains

Reproduction/example

NA

Steps to reproduce

Hard to reproduce consistently manually as it only really happens when the interaction is very fast, but it has been possible to see this consistently in automations.

The key part to the issue is that the submenu items are being created in async manner, so the refs are not being maintained.

Suggested Severity

Severity 3 = User can complete task, and/or has a workaround within the user experience of a given component.

Application/PAL

No response

Code of Conduct

@tay1orjones
Copy link
Member

The key part to the issue is that the submenu items are being created in async manner, so the refs are not being maintained.

Short of fixing that issue we could at least avoid the error with some optional chaining.

@tay1orjones tay1orjones added status: help wanted 👐 good first issue 👋 Used by GitHub to elevate contribution opportunities needs: community contribution Due to roadmap and resource availability, we are looking for outside contributions on this issue. labels May 13, 2024
@Kilian-Collender
Copy link
Contributor Author

I'm happy to add the optional chaining @tay1orjones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue 👋 Used by GitHub to elevate contribution opportunities needs: community contribution Due to roadmap and resource availability, we are looking for outside contributions on this issue. severity: 2 User cannot complete task, and/or no workaround status: help wanted 👐 type: bug 🐛
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants