Skip to content

fix: close members dropdown when clicking outside in Create Channel m…#39633

Open
Pavani12314 wants to merge 5 commits intoRocketChat:developfrom
Pavani12314:fix/members-dropdown-close-39620
Open

fix: close members dropdown when clicking outside in Create Channel m…#39633
Pavani12314 wants to merge 5 commits intoRocketChat:developfrom
Pavani12314:fix/members-dropdown-close-39620

Conversation

@Pavani12314
Copy link
Copy Markdown

@Pavani12314 Pavani12314 commented Mar 14, 2026

Description

Fixes #39620

The members dropdown in the Create Channel modal was not closing
when clicking outside of it.

Root Cause

The UserAutoCompleteMultiple component had no click-outside handler.

Fix

Added a useEffect with a mousedown event listener that clears
the filter and closes the dropdown when clicking outside the component.

Steps to Test

  1. Open Create Channel modal
  2. Click Members field and type a name
  3. Click outside the dropdown
  4. Dropdown should now close

Summary by CodeRabbit

  • Bug Fixes

    • Members dropdown (Create Channel) now closes when clicking outside and the user filter is cleared.
  • Refactor

    • Minor internal structure added to support outside-click behavior without changing the component's public API or props.
  • Chores

    • Release metadata added for a patch release.

Proposed changes (including videos or screenshots)

📹 Screen recording will be added shortly.
Currently facing memory constraints in the development environment.

Before fix: Dropdown stays open when clicking outside the Members field
After fix: Dropdown closes when clicking outside

The bug can be reproduced as described in issue #39620

@Pavani12314 Pavani12314 requested a review from a team as a code owner March 14, 2026 18:04
Copilot AI review requested due to automatic review settings March 14, 2026 18:04
@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 14, 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

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 14, 2026

🦋 Changeset detected

Latest commit: d2116cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/http-router Patch
@rocket.chat/livechat Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

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

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 14, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 14, 2026

Walkthrough

Adds outside-click detection to UserAutoCompleteMultiple so the component clears its filter and closes the members dropdown when clicking outside. Also adds two changeset files to record a patch release for the fix.

Changes

Cohort / File(s) Summary
User autocomplete component
apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
Added useRef and useOutsideClick, introduced containerRef wrapper around MultiSelectFiltered, and clear-filter logic on outside click. Removed an in-place comment; public API unchanged.
Release metadata
.changeset/dry-avocados-rush.md, .changeset/fix-members-dropdown-close.md
Added two changeset entries bumping @rocket.chat/meteor for a patch release and documenting the fix for the members dropdown closing behavior (metadata only).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: closing the members dropdown when clicking outside in the Create Channel modal, which is the primary fix in this PR.
Linked Issues check ✅ Passed The code changes implement the required fix by adding click-outside detection to UserAutoCompleteMultiple component to close the dropdown, directly addressing issue #39620's requirement.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the members dropdown close behavior; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Copy Markdown
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.

No issues found across 1 file


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Copy link
Copy Markdown
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

Fixes the Create Channel modal “Members” autocomplete dropdown not closing when clicking outside by adding an outside-click handler to UserAutoCompleteMultiple.

Changes:

  • Added a ref-wrapped container around MultiSelectFiltered to detect clicks outside the component.
  • Added an effect that listens for mousedown events and clears the filter when the click occurs outside the component.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
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/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx`:
- Around line 91-101: The outside-click handler using containerRef and
document.addEventListener incorrectly closes the filter because
MultiSelectFiltered renders its dropdown in a Portal; replace this manual logic
with the useOutsideClick hook from `@rocket.chat/fuselage-hooks`: remove the
useEffect, keep containerRef and setFilter, call useOutsideClick(containerRef,
() => setFilter('')) (or equivalent signature used in the codebase) so
portal-rendered clicks are handled correctly; ensure imports include
useOutsideClick and confirm the same behavior as
NavBarSearchListbox/EmojiPicker/DropDownListWrapper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 652308a1-38f9-4582-91eb-c715ce541ad6

📥 Commits

Reviewing files that changed from the base of the PR and between eb3ad21 and eb28c97.

📒 Files selected for processing (1)
  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.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). (2)
  • GitHub Check: Agent
  • 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/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
🧠 Learnings (1)
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
🔇 Additional comments (3)
apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx (3)

6-6: Hook import update looks correct.

useRef and useEffect are correctly added for the new outside-click behavior.


105-130: Container ref wiring is clean and minimal.

Wrapping MultiSelectFiltered with a ref container is a straightforward integration for outside-click handling.


135-135: Memoized export remains appropriate.

No concerns with the final export after this change.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@coderabbitai coderabbitai bot removed the type: bug label Mar 14, 2026
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx (1)

91-124: Please add a regression test for this interaction path.

Given this was a user-facing bug, adding a focused test (component or e2e) for “type in Members → click outside → dropdown closes/filter clears” would protect against regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx`
around lines 91 - 124, Add a regression test (component or e2e) that simulates
typing into UserAutoCompleteMultiple, verifies the dropdown/opened options from
MultiSelectFiltered are visible, then triggers a click outside the container
referenced by containerRef (the useOutsideClick handler) and asserts that the
filter state is cleared and the dropdown is closed; target the
UserAutoCompleteMultiple component, exercise the renderSelected path
(selectedCache) and ensure after the outside click the filter prop passed into
MultiSelectFiltered is empty and options are not visible.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx`:
- Around line 91-124: Add a regression test (component or e2e) that simulates
typing into UserAutoCompleteMultiple, verifies the dropdown/opened options from
MultiSelectFiltered are visible, then triggers a click outside the container
referenced by containerRef (the useOutsideClick handler) and asserts that the
filter state is cleared and the dropdown is closed; target the
UserAutoCompleteMultiple component, exercise the renderSelected path
(selectedCache) and ensure after the outside click the filter prop passed into
MultiSelectFiltered is empty and options are not visible.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c7e4a7ef-80c7-4618-9a8d-b6d82dfa05c2

📥 Commits

Reviewing files that changed from the base of the PR and between eb28c97 and 6d6d81b.

📒 Files selected for processing (1)
  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
📜 Review details
🧰 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/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
🧠 Learnings (4)
📚 Learning: 2026-03-06T18:10:23.330Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:23.330Z
Learning: In the RocketChat/Rocket.Chat `packages/gazzodown` package and more broadly, the HTML `<code>` element has an implicit ARIA role of `code` per WAI-ARIA 1.3, and `testing-library/dom` / jsdom supports it. Therefore, `screen.getByRole('code')` / `screen.findByRole('code')` correctly locates `<code>` elements without needing an explicit `role="code"` attribute. Do NOT flag `findByRole('code')` as invalid in future reviews.

Applied to files:

  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
📚 Learning: 2026-03-04T14:16:49.202Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39304
File: packages/ui-contexts/src/ActionManagerContext.ts:26-26
Timestamp: 2026-03-04T14:16:49.202Z
Learning: In `packages/ui-contexts/src/ActionManagerContext.ts` (TypeScript, RocketChat/Rocket.Chat), the `disposeView` method in `IActionManager` uses an intentionally explicit union `UiKit.ModalView['id'] | UiKit.BannerView['viewId'] | UiKit.ContextualBarView['id']` to document which view types are accepted, even though all constituents resolve to the same primitive. The inline `// eslint-disable-next-line typescript-eslint/no-duplicate-type-constituents` comment is intentional and should not be flagged or removed.

Applied to files:

  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
📚 Learning: 2026-02-24T19:36:55.089Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/page-objects/fragments/home-content.ts:60-82
Timestamp: 2026-02-24T19:36:55.089Z
Learning: In RocketChat/Rocket.Chat e2e tests (apps/meteor/tests/e2e/page-objects/fragments/home-content.ts), thread message preview listitems do not have aria-roledescription="message", so lastThreadMessagePreview locator cannot be scoped to messageListItems (which filters for aria-roledescription="message"). It should remain scoped to page.getByRole('listitem') or mainMessageList.getByRole('listitem').

Applied to files:

  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
📚 Learning: 2026-03-09T18:39:21.178Z
Learnt from: Harxhit
Repo: RocketChat/Rocket.Chat PR: 39476
File: apps/meteor/server/methods/addAllUserToRoom.ts:0-0
Timestamp: 2026-03-09T18:39:21.178Z
Learning: In apps/meteor/server/methods/addAllUserToRoom.ts, the implementation uses a single cursor pass (Users.find(userFilter).batchSize(100)) that collects both the full user objects (collectedUsers: IUser[]) and their usernames (usernames: string[]) in one iteration. `beforeAddUserToRoom` is then called once with the full usernames batch (preserving batch-validation semantics), and the subsequent subscription/message processing loop iterates over the same stable `collectedUsers` array — no second DB query is made. This avoids any race condition between validation and processing while preserving the original batch-validation behavior.

Applied to files:

  • apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx
🔇 Additional comments (2)
apps/meteor/client/components/UserAutoCompleteMultiple/UserAutoCompleteMultiple.tsx (2)

91-95: Good fix: outside-click handling is now correctly centralized via useOutsideClick.

This cleanly addresses the dropdown-close behavior without manual document listener management.


99-124: The ref wrapper is a safe, minimal integration point for the outside-click hook.

No API surface change, and the behavior stays scoped to this component.

@karanXtream
Copy link
Copy Markdown

can you add a screen-shot too , I think this query already raised

@coderabbitai coderabbitai bot removed the type: bug label Mar 15, 2026
@vmridul
Copy link
Copy Markdown

vmridul commented Mar 15, 2026

Hi @Pavani12314, I think there is already a PR for this issue with a better fix in fuselage repo: RocketChat/fuselage#1870

@Pavani12314
Copy link
Copy Markdown
Author

Pavani12314 commented Mar 15, 2026 via email

@DammyCodes-all
Copy link
Copy Markdown

@Pavani12314 I'm the author of the fix in the fuselage repo. I haven't been able to contact any one of the maintainers to discuss getting merged could you please help me with that?

@Pavani12314
Copy link
Copy Markdown
Author

Hi! I tested the behavior again and observed that:

  • The dropdown closes when selecting a single option
  • It remains open when selecting multiple options

I wanted to confirm whether this is the intended behavior for multi-select components, or if it should close after each selection.

Happy to update or close the PR based on feedback. Thanks!

@Pragatigupta2508
Copy link
Copy Markdown

This looks like a very useful fix. While going through the issue flow, I was wondering if the same outside-click behavior has been checked for keyboard navigation / focus loss cases as well, since that could affect accessibility and modal consistency.

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.

Members dropdown does not close when clicking outside in Create Channel modal

7 participants