Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should auto focus in drop-down menu #2234

Merged
merged 2 commits into from
Jul 12, 2023
Merged

fix: should auto focus in drop-down menu #2234

merged 2 commits into from
Jul 12, 2023

Conversation

zhangzhonghe
Copy link
Contributor

Description (Bug 描述)

Steps to reproduce (复现步骤)

image

Expected behavior (预期行为)

期望这里的输入框在显示的时候能够自动 focus

Actual behavior (实际行为)

没有自动 focus

Related issues (相关 issue)

antd 官方 BUG:ant-design/ant-design#41239

Reason (原因)

antd v5 版本的 BUG, 原因暂未知

Solution (解决方案)

  1. 通过 useRef 获取 input 实例
  2. input 初次渲染时调用 input.focus()
  3. 使用 IntersectionObserver API 监听 input 何时显示
  4. input 显示时调用 input.focus

注意:需要当前系统的焦点在浏览器页面中,如果焦点在浏览器外面则不会触发自动 focus。等官方修复后可能需要重构。

其它

close T-884

@height
Copy link

height bot commented Jul 11, 2023

This pull request has been linked to and will mark 1 task as "Done" when merged:

  • T-884 创建区块下拉菜单优化(光标自动聚焦搜索框) (unlink task)

💡Tip: You can link multiple Height tasks to a pull request.

@chenos chenos merged commit 57507b3 into main Jul 12, 2023
4 checks passed
@chenos chenos deleted the T-884 branch July 12, 2023 00:39
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.

None yet

2 participants