Skip to content

fix(navbar): prevent Escape key from resetting search when not active#39463

Open
gauravsingh001-cyber wants to merge 2 commits intoRocketChat:developfrom
gauravsingh001-cyber:fix/navbar-search-escape-key
Open

fix(navbar): prevent Escape key from resetting search when not active#39463
gauravsingh001-cyber wants to merge 2 commits intoRocketChat:developfrom
gauravsingh001-cyber:fix/navbar-search-escape-key

Conversation

@gauravsingh001-cyber
Copy link

@gauravsingh001-cyber gauravsingh001-cyber commented Mar 9, 2026

FIx #39462

Description

The Escape key listener in NavBarSearch.tsx was attached globally using tinykeys(window). Because of this, pressing Escape anywhere in the application triggered handleEscSearch(), even when the search input was not focused or the search dropdown was not open.

This PR adds a guard to ensure that the Escape handler only runs when the search input is active.

Steps to reproduce

  1. Start the Rocket.Chat development server

  2. Open the application

  3. Do not open the Navbar search

  4. Focus the chat input

  5. Press Escape

Actual behavior

Escape triggers handleEscSearch() even when the search is not active.

Expected behavior

Escape should reset the search only when the search input is focused or the search dropdown is open.

solution.10.mp4

Summary by CodeRabbit

  • Bug Fixes
    • Refined escape key handling in the search bar to be context-aware. The escape key now checks whether the search input is focused before acting, preventing unintended closures or interference with other interactive elements.
    • Improved focus/interaction reliability so the search list responds more predictably across keyboard and focus transitions.

@gauravsingh001-cyber gauravsingh001-cyber requested a review from a team as a code owner March 9, 2026 07:26
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 1dc47fe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Mar 9, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 46693733-a03a-4197-a5da-2edb3c56d363

📥 Commits

Reviewing files that changed from the base of the PR and between e2e6522 and 1dc47fe.

📒 Files selected for processing (1)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx

Walkthrough

The Escape key handler in NavBarSearch now checks whether the currently focused element is the search trigger (or the list is open) before processing Escape, avoiding global Escape from resetting the navbar search when the input is not active.

Changes

Cohort / File(s) Summary
NavBar Search Escape Handler
apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx
Escape key listener updated to conditionally return early when the focused element is not the trigger and the list is closed; effect dependency array adjusted to include state and minor control-flow/bracing changes.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing the Escape key from resetting search when the search feature is not active.
Linked Issues check ✅ Passed The code changes implement the core requirement from #39462: adding a guard condition to the Escape handler so it only runs when the search input is focused or dropdown is open.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the Escape key behavior in NavBarSearch.tsx and are within the scope of the linked issue.
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.


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.

@gauravsingh001-cyber gauravsingh001-cyber changed the title Fix: Prevent global Escape key from resetting Navbar search when search is not active fix(navbar): prevent Escape key from resetting search when not active Mar 9, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx">

<violation number="1" location="apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx:66">
P2: Escape no longer closes search when focus moves into the open listbox (options), because the global handler now ignores cases where the input is not active and the listbox handler doesn’t handle Escape.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx`:
- Around line 64-69: The Escape handler currently only triggers when the input
element equals triggerRef.current, but per PR it should also close the dropdown
when state.isOpen is true; update the condition inside the 'Escape' case to
allow the handler to run when either document.activeElement ===
triggerRef.current OR state.isOpen is true, keep calling event.preventDefault()
and handleEscSearch(), and then add state (or state.isOpen) to the useEffect
dependency array so the effect updates correctly; reference triggerRef,
handleEscSearch, and state.isOpen when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 46a8d6e7-adb8-446a-a3e8-45dd7b855810

📥 Commits

Reviewing files that changed from the base of the PR and between 4f43a85 and e2e6522.

📒 Files selected for processing (1)
  • apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/navbar/NavBarSearch/NavBarSearch.tsx

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Global Escape key resets Navbar search even when search input is not active

1 participant