Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

The keyboard navigation in ContextMenu.tsx crashes when filteredActions is empty due to modulo-by-zero and negative index operations.

Changes

  • Added guard conditions to handleKeyDown for ArrowDown/ArrowUp navigation
  • Prevents (prev + 1) % 0NaN and 0 - 1-1 when no results exist
case "ArrowDown":
case "Tab":
  if (filteredActions.length > 0) {
    setSelectedIndex((prev) => (prev + 1) % filteredActions.length);
  }
  break;
case "ArrowUp":
  if (filteredActions.length > 0) {
    setSelectedIndex((prev) =>
      prev === 0 ? filteredActions.length - 1 : prev - 1,
    );
  }
  break;

The existing useEffect already resets selectedIndex to 0 when filteredActions changes, so state remains consistent.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Coder-Harshit <93333205+Coder-Harshit@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on limiting target node handles to one input Fix keyboard navigation crash when context menu has no filtered results Dec 19, 2025
Copilot AI requested a review from Coder-Harshit December 19, 2025 11:39
@Coder-Harshit Coder-Harshit marked this pull request as ready for review December 19, 2025 11:39
Copilot AI review requested due to automatic review settings December 19, 2025 11:39
@Coder-Harshit Coder-Harshit merged commit fe9105d into ux Dec 19, 2025
2 checks passed
@Coder-Harshit Coder-Harshit deleted the copilot/sub-pr-61 branch December 19, 2025 11:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in keyboard navigation when the context menu has no filtered results. The issue occurred when users pressed arrow keys with an empty search result, causing NaN from modulo-by-zero operations and negative indices.

  • Added guard conditions to prevent keyboard navigation when filteredActions is empty
  • Guards prevent (prev + 1) % 0NaN and 0 - 1-1 edge cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants