Skip to content

Keep multiple select open on clear#1225

Open
QDyanbing wants to merge 1 commit into
react-component:masterfrom
QDyanbing:keep-open-on-clear
Open

Keep multiple select open on clear#1225
QDyanbing wants to merge 1 commit into
react-component:masterfrom
QDyanbing:keep-open-on-clear

Conversation

@QDyanbing

@QDyanbing QDyanbing commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

变更内容

  • 调整 clear icon 的鼠标按下处理:多选模式下点击清空不再触发关闭弹层。
  • 补充多选模式回归测试,覆盖 defaultOpen + allowClear 清空后弹层保持展开的场景。

问题原因

clear icon 会标记 _select_lazy,此前内部逻辑在弹层已展开时会统一关闭弹层;这对单选仍然合理,但会打断多选用户清空后继续选择的连续操作。

影响

  • multiple / tags 清空后保持当前展开状态。
  • 非多选清空时仍保留原有关闭行为。

验证

  • npm test -- tests/Multiple.test.tsx tests/Select.test.tsx --runInBand --silent
  • npm run tsc

关联 ant-design/ant-design#58336

Summary by CodeRabbit

  • Bug Fixes

    • 修复了多选选择框使用清除按钮时下拉菜单意外关闭的问题。
  • Tests

    • 新增测试用例验证多选模式下清除值后下拉菜单保持打开状态。

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

修改 SelectInput 组件的鼠标处理逻辑,在 multiple 模式下点击清除按钮时保持弹出层打开。调整条件判断从 triggerOpen 改为 triggerOpen && !multiple,并新增测试用例验证该行为。

Changes

Multiple 模式清除行为修复

Layer / File(s) Summary
SelectInput 关闭条件修改
src/SelectInput/index.tsx
onInternalMouseDown 的 lazy 分支中,将 toggleOpen(false) 的触发条件从 triggerOpen 修改为 triggerOpen && !multiple,使得仅在单选模式下才会执行关闭操作。注释更新为"单选点击清除图标也应关闭"。
Multiple 清除时弹出层保持打开的测试
tests/Multiple.test.tsx
新增测试用例 keeps popup open when clearing values,验证在 multiple 模式下点击清除按钮后,下拉弹出层保持打开状态,且 onPopupVisibleChange 不会以 false 的形式被调用。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • react-component/select#1214: 两者都在 src/SelectInput/index.tsx 调整"下拉关闭时机/toggleOpen(false)触发条件",核心都是在 multiple 场景下避免因输入/清除相关的鼠标交互触发关闭。

  • react-component/select#1183: 两者都在调整 triggerOpen/mouseDown 相关的关闭时机与事件语义,属于同一类底层关闭行为联动修改。

  • react-component/select#1166: 本 PR 进一步细化 src/SelectInput/index.tsx 的 mouseDown/打开-关闭逻辑,属于同一类 SelectInput 交互结构重构。

Suggested reviewers

  • zombieJ
  • afc163

Poem

🐰 清除按钮轻轻点,
Multiple 模式别关闭,
弹出层稳稳站,
单选才能说拜拜,
逻辑改得恰恰好!✨

🚥 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 标题清晰准确地反映了本次变更的核心内容——在多选模式下点击清空按钮时保持弹层展开。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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.

@QDyanbing QDyanbing marked this pull request as ready for review June 12, 2026 00:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the SelectInput component to ensure that the dropdown popup remains open when the clear icon is clicked in multiple-select mode, updating the condition to only close the popup for single-select mode. Additionally, a unit test has been added to verify this behavior. There are no review comments, and I have no further feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.44%. Comparing base (7876c6c) to head (bc6943d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1225   +/-   ##
=======================================
  Coverage   99.44%   99.44%           
=======================================
  Files          31       31           
  Lines        1266     1266           
  Branches      442      462   +20     
=======================================
  Hits         1259     1259           
  Misses          7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/Multiple.test.tsx (1)

111-130: ⚡ Quick win

建议增强测试完整性:验证清除操作是否实际清空了值。

当前测试正确验证了弹出层保持打开状态,但未验证清除操作是否真的将 defaultValue={['1', '2']} 清空。建议添加对清除后选中值的断言,以确保清除功能本身正常工作,而不仅仅是弹出层状态。

💡 建议的测试增强
  it('keeps popup open when clearing values', () => {
+   const onChange = jest.fn();
    const onPopupVisibleChange = jest.fn();
    const { container } = render(
      <Select
        mode="multiple"
        defaultOpen
        defaultValue={['1', '2']}
        allowClear
+       onChange={onChange}
        onPopupVisibleChange={onPopupVisibleChange}
      >
        <Option value="1">One</Option>
        <Option value="2">Two</Option>
      </Select>,
    );

    fireEvent.mouseDown(container.querySelector('.rc-select-clear'));

    expectOpen(container, true);
    expect(onPopupVisibleChange).not.toHaveBeenCalledWith(false);
+   expect(onChange).toHaveBeenCalledWith([], expect.anything());
  });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/Multiple.test.tsx` around lines 111 - 130, The test "keeps popup open
when clearing values" currently only asserts the popup stays open and
onPopupVisibleChange isn't called with false; update it to also verify the clear
actually removed the selections: after calling
fireEvent.mouseDown(container.querySelector('.rc-select-clear')), add an
assertion that selected items are gone (e.g. query for selection tags like
'.rc-select-selection-item' returns length 0 or the text "One"/"Two" is not
present) or that the Select's value/input is empty; keep the existing expectOpen
and onPopupVisibleChange assertions intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/Multiple.test.tsx`:
- Around line 111-130: The test "keeps popup open when clearing values"
currently only asserts the popup stays open and onPopupVisibleChange isn't
called with false; update it to also verify the clear actually removed the
selections: after calling
fireEvent.mouseDown(container.querySelector('.rc-select-clear')), add an
assertion that selected items are gone (e.g. query for selection tags like
'.rc-select-selection-item' returns length 0 or the text "One"/"Two" is not
present) or that the Select's value/input is empty; keep the existing expectOpen
and onPopupVisibleChange assertions intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ee5d547-4211-480c-9b08-2500c8ddc2f4

📥 Commits

Reviewing files that changed from the base of the PR and between 7876c6c and bc6943d.

📒 Files selected for processing (2)
  • src/SelectInput/index.tsx
  • tests/Multiple.test.tsx

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.

1 participant