Keyed reorder moves the row that moved earlier, so a focused input in it loses focus (React keeps focus)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 75/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, react, typescript
- Área
- accessibility, frontend, testing
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 581
- Forks
- 28
- Merge medio
- 13 h 48 min
- PR fusionados (30 d)
- 45
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/redact
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/redact#142 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 20/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/redact
Issues similares
-
inference/go type/feature
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
anomalyco/opencode#65148 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
truapi-release
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
paritytech/product-sdk#529 ·
Los mantenedores suelen responder en 1 día
-
Add: Mansudae TVAbiertoapproved check:passed streams:add
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Los mantenedores suelen responder en 1 día
-
[Perf] Canvas layer composition is quadratic: splitRenderLayers re-copies the node array per nodeAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
devlikeapro/waha#2369 ·
Los mantenedores suelen responder en 5 días