react-component / react-component/select

模态框中的下拉菜单,打开时按下 ESC 会导致模态框也被关闭,未阻止事件传播

Open
#542 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
938
Forks
482
Avg merge
15h 8m
Merged PRs (30d)
2

Description

最近在搭配使用下拉选择和模态框,我发现当下拉菜单处于下拉状态时,按下 ESC 会导致模态框也跟着被关闭。如下图,左边的是我二次封装的,在按下 ESC 时处理了一下,阻止了事件向外传播,右边的是直接引用的,按下 ESC 时模态框也会被关闭(引入的都是 Antd,但应该不影响)。

复现代码:https://codesandbox.io/s/brave-sanne-11rpo

rc-select 关闭控制问题复现

我记得以前是不会这样的,翻看了源码,发现在早期版本中有下面的阻止事件传播代码,我尝试把这段代码添加到现在的版本上,发现是起作用的。不知道去掉这个逻辑的原因是什么?如果能加回来,感觉体验更好一些。

https://github.com/react-component/select/blob/50ce1a8e56d36444d6cc777abc2e0042669cba6d/src/Select.tsx#L402

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the current ESC-key handling in src/Select.tsx and compare it with the historical implementation linked in the issue. Reproduce the interaction in the linked CodeSandbox; done when pressing ESC closes the open dropdown without also closing its parent modal.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.