Skip to content

fix: prevent infinite loop in MenuBar navigation when all items disabled#1611

Merged
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
pradeep0153:fix/1606-menubar-infinite-loop
Jun 23, 2026
Merged

fix: prevent infinite loop in MenuBar navigation when all items disabled#1611
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
pradeep0153:fix/1606-menubar-infinite-loop

Conversation

@pradeep0153

@pradeep0153 pradeep0153 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixes an issue where MenuBar would enter an infinite loop when selectNextMenu or selectPrevItem was triggered on a menu with entirely disabled items. The fix introduces an early return guard checking items.every(i => i.disabled). Resolves #1606.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed MenuBar navigation to properly handle cases where menus have no available items or all items are disabled, improving navigation responsiveness and preventing unresponsive looping behavior.

@pradeep0153 pradeep0153 requested a review from Karanjot786 as a code owner June 19, 2026 04:37
@github-actions github-actions Bot added type:bug +10 pts. Bug fix. area:ui @termuijs/ui needs-star PR author has not starred the repo. labels Jun 19, 2026
@github-actions

Copy link
Copy Markdown

Hi @pradeep0153 👋

Star this repo before your PR merges.

Why? GSSoC 2026 contributors who star get priority review and points credit. After you star, push any commit (or re-run this check). The needs-star label lifts automatically.

Thanks for your contribution to TermUI.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3cdb1513-e8f0-40b8-8ebe-d368382a12ff

📥 Commits

Reviewing files that changed from the base of the PR and between 550e9c6 and cab24be.

📒 Files selected for processing (1)
  • packages/ui/src/MenuBar.ts

📝 Walkthrough

Walkthrough

In MenuBar.ts, the early-return guards in _selectNextItem() and _selectPrevItem() are updated to also exit when every item in the active menu is disabled, preventing an infinite loop during arrow-key navigation.

Changes

MenuBar Disabled-Item Navigation Fix

Layer / File(s) Summary
Expand early-exit guards in navigation methods
packages/ui/src/MenuBar.ts
_selectNextItem() (line 72) and _selectPrevItem() (line 87) each add a check for all items being disabled alongside the existing empty-items check, so navigation returns immediately instead of looping.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 When every door is locked and none will turn,
No need to spin in circles, that's my concern.
A quick peek down the list — all disabled, I see!
Return at once, dear loop, and set the process free.
✨ Two lines changed, a hang erased, hooray!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately summarizes the main change: preventing an infinite loop in MenuBar navigation when all items are disabled.
Description check ✅ Passed The PR description clearly states the issue, the fix mechanism, and the related issue number, though it lacks the formal template structure with sections like 'Related Issue', 'Which package(s)?', and 'Type of Change'.
Linked Issues check ✅ Passed The code changes directly address issue #1606 by introducing early-return guards that check for all-disabled items, preventing the infinite loop in MenuBar navigation functions.
Out of Scope Changes check ✅ Passed The changes are focused and limited to MenuBar's item navigation logic (_selectNextItem and _selectPrevItem), addressing only the infinite loop issue without introducing unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉 Thanks for your first PR to TermUI, @pradeep0153.

Before your PR merges:

  1. Star the repo. Required. The star-check job blocks your merge otherwise.
  2. ✅ All checks green: build, test, typecheck.
  3. 🏷 PR title follows type: short description. Example: fix: handle empty list.
  4. 🔗 Link your closing issue in the description.

GSSoC 2026 points come from labels after merge:

  • gssoc:approved. +50 base points.
  • level:beginner / intermediate / advanced / critical. +20 / +35 / +55 / +80.
  • quality:clean / exceptional. x 1.2 / x 1.5.
  • type:*. Stackable bonus.

Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.

🚀 Welcome to the cohort.

@Karanjot786 Karanjot786 merged commit 277e6c7 into Karanjot786:main Jun 23, 2026
7 of 10 checks passed
@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. quality:clean x 1.2 multiplier. Clean implementation. labels Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ui @termuijs/ui gssoc:approved Approved PR. Earns +50 base points. level:beginner +20 pts. Entry-level task. needs-star PR author has not starred the repo. quality:clean x 1.2 multiplier. Clean implementation. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MenuBar navigation enters an infinite loop if all menu items are dynamically disabled

2 participants