Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Focus and keyboard navigation do not work in search results when disabled parents

未关闭
#652 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
react, typescript

调研方向

从 issue 中描述的入口点 getFirstMatchingNode 开始,使用链接的 CodeSandbox 重现该行为,并比较父元素被禁用和父元素启用的情况。验证匹配的已启用子元素可以获得焦点并使用 Enter 进行选择,然后在 repository 中存在相关测试时,添加或更新回归测试覆盖。

由索引模型根据 Issue 内容生成。

描述

What is expected?

When the tree select search is used, focus is given to the first element, users can press 'Enter' to select it or use 'up' and 'down' keys to navigate other search results

Disabled elements in the search should not be given focus, but if their children are enabled their children should still be focused in search results

What is actually happening?

Any element with a disabled parent somewhere in their hierarchy is not given focus when searching, 'Enter' key will select the first element in the tree instead

This is bad UX but also not good for accessibility

I am using master from this repo during testing

Steps to reproduce
I have a demo sandbox here made with AntD but exact behaviour comes from rc-tree-select, I can adjust the demo if needed: https://codesandbox.io/p/devbox/confident-resonance-8jv7cz

The demo shows two cases, one working (No disabled parents) and one broken (Disabled parent)

To show the component not working:

Click on the treeselect search
Search for '1' (Or '2', or '3')
The child element gets focus, pressing enter on keyboard does nothing

To show the component working as expected:

Click on the treeselect search
Search for '3' (Or '4', or '5')
The child element gets focus, pressing enter on keyboard selects element

Suggested code fix - even if a parent is disabled or not selectable, check children

// ========================== Get First Selectable Node ==========================
const getFirstMatchingNode = (nodes: EventDataNode<any>[]): EventDataNode<any> | null => {
  for (const node of nodes) {
-    if (node.disabled || node.selectable === false) {
-      continue;
-    }
-
-    if (searchValue) {
-      if (filterTreeNode(node)) {
-        return node;
-      }
-    } else {
-      return node;
-    }
+    const isNodeSelectable = !node.disabled && node.selectable !== false;
+
+    if (isNodeSelectable) {
+      if (searchValue) {
+        if (filterTreeNode(node)) {
+          return node;
+        }
+      } else {
+        return node;
+      }
+    }
 
     if (node[fieldNames.children]) {
       const matchInChildren = getFirstMatchingNode(node[fieldNames.children]);
       if (matchInChildren) {
         return matchInChildren;
       }
     }
   }
   return null;
};

Demo before;

Image

Demo after;

Image

Initially created as an antD issue

Please let me know if I can provide any more information

主要语言
TypeScript
星标
312
派生
204
平均合并
37 分钟
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react-component/tree-select 的其他 Issue

查看 react-component/tree-select 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。