Focus and keyboard navigation do not work in search results when disabled parents
还没有人认领这个 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;
Demo after;
Initially created as an antD issue
Please let me know if I can provide any more information
- 主要语言
- TypeScript
- 星标
- 312
- 派生
- 204
- 平均合并
- 37 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react-component/tree-select 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
react-component/tree-select#528 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
react-component/tree-select#485 ·
-
难度 4/5 3-5 天 新手友好度 28/100
react-component/tree-select#466 ·
-
DFS这里是否能调整为尾递归 未关闭
难度 3/5 1-2 天 新手友好度 35/100
react-component/tree-select#454 ·
-
难度 2/5 1-3 小时 新手友好度 48/100
react-component/tree-select#437 · 3 个 reaction ·
查看 react-component/tree-select 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
vercel-labs/just-bash#464 ·
-
looksLikeSlug() is ASCII-only, so non-Latin entity slugs (e.g. Korean) skip exact match and collapse 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 1/5 1 小时以内 新手友好度 90/100
TanStack/tanstack.com#1293 ·