Keyed reorder moves the row that moved earlier, so a focused input in it loses focus (React keeps focus)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, react, typescript
- 领域
- accessibility, frontend, testing
调研方向
Start by reading placeDomsInOrder in dist/dom/reconcile.js and the keyed reorder test setup using Vitest, jsdom, and Testing Library described in the issue. Reproduce [a, b] to [b, a] with focus on b, then inspect which DOM row the reconciliation moves. Done when the reorder preserves the focused input and the regression test passes.
由索引模型根据 Issue 内容生成。
描述
Version: @tanstack/redact 0.3.0
When a keyed list is reordered, Redact moves a different DOM node than React does. If the node it moves contains the focused element, the browser blurs it (moving a focused node with insertBefore drops focus in Chromium, Firefox and WebKit), so focus ends up on <body>. React keeps focus in the same case.
Repro (Vitest + jsdom + Testing Library)
import { render, screen } from '@testing-library/react';
import { expect, test } from 'vitest';
test('a keyed reorder keeps focus in the row that moves earlier', () => {
const list = (order) => (
<div>{order.map((id) => <div key={id}><input aria-label={id} /></div>)}</div>
);
const { rerender } = render(list(['a', 'b']));
const b = screen.getByLabelText('b');
b.focus();
rerender(list(['b', 'a']));
expect(screen.getByLabelText('b')).toBe(b); // passes on both: the node is kept
expect(document.activeElement).toBe(b); // React: b. Redact: body
});
React 19.2.8 passes; Redact 0.3.0 fails the focus assertion.
Where it seems to come from
For [a, b] -> [b, a], React leaves the rows whose relative order is unchanged in place and moves the ones that fall behind (it moves a). placeDomsInOrder in dist/dom/reconcile.js walks backwards and calls insertBefore on rows that move earlier (it moves b), which takes focus away from the row the user is working in. The same happens when an item is moved to the top of a list.
Matching React's placement (walk the new order forwards, track the highest current DOM index among rows left in place, and move only rows whose current index is below it) would keep focus. moveBefore could help where it exists, but jsdom and some browsers don't have it.
Real-world impact
Keyboard users lose focus when the row they're in moves up: "move up" buttons, lists that re-sort, or lists that put the newest item first while a control in a row has focus. Scroll position and media inside the moved row can also reset.
- 主要语言
- TypeScript
- 星标
- 581
- 派生
- 28
- 平均合并
- 13 小时 48 分钟
- 30 天内合并 PR
- 45
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/redact 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 4/5 1-2 天 新手友好度 35/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 20/100
维护者通常 1 天内回复
相似的 Issue
-
inference/go type/feature
难度 1/5 1-3 小时 新手友好度 72/100
anomalyco/opencode#65148 · 1 条评论 ·
维护者通常 1 天内回复
-
truapi-release
难度 2/5 1-3 小时 新手友好度 72/100
paritytech/product-sdk#529 ·
维护者通常 1 天内回复
-
Add: Mansudae TV未关闭approved check:passed streams:add
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per node未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
devlikeapro/waha#2369 ·
维护者通常 5 天内回复