`autofocus` prop has no effect on initial render in React components (e.g. `<TextField autofocus />`)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
Start by reading DelegateFocusMixin and the @lit/react createComponent path, then compare the ordering used by createComponentWithOrderedProps. Reproduce the React example and verify that TextField receives focus on initial render while preserving the plain-HTML behavior; existing relevant tests, if present, should cover both property-setting orders.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
When a field is rendered from React with the autofocus prop, it does not receive focus on initial render. Focus stays on <body>.
The prop is set on the element (element.autofocus === true afterwards), but it has no effect. DelegateFocusMixin reads autofocus only once, in ready(). That runs when the element is connected. The React wrapper (@lit/react createComponent) assigns element properties in a useLayoutEffect, after React has inserted the element into the DOM. So ready() has already run with autofocus === false.
Expected outcome
<TextField autofocus /> focuses the field's input on initial render, the same as in plain HTML, where autofocus is set before the element is connected.
Minimal reproducible example
import { TextField } from '@vaadin/react-components/TextField.js';
export default function View() {
return <TextField label="Email" autofocus />;
}
Open the view, then check document.activeElement → BODY.
Without React, the result depends on when autofocus is set:
const a = document.createElement('vaadin-text-field');
a.autofocus = true; // set BEFORE connecting
document.body.append(a); // → gets focus ✅
const b = document.createElement('vaadin-text-field');
document.body.append(b);
b.autofocus = true; // set AFTER connecting (what the React wrapper does)
// → no focus ❌
Workaround
Call focus() from a ref after mount, deferred by one animation frame:
const ref = useRef<TextFieldElement>(null);
useEffect(() => {
const f = requestAnimationFrame(() => ref.current?.focus());
return () => cancelAnimationFrame(f);
}, []);
Possible fixes
DelegateFocusMixin: also react toautofocuschanging totruebefore the element has been focused or interacted with (e.g. an observer, or reading it infirstUpdated), or@vaadin/react-components: applyautofocusbefore the element is connected (likecreateComponentWithOrderedPropsdoes for other order-sensitive props).
Environment
- Vaadin 25.0.9 (
@vaadin/react-components25.0.9,@vaadin/text-field25.0.9,@vaadin/a11y-base25.0.9) @lit/react1.0.8, React 19.2.4- Hilla file router, Spring Boot 4.0.6, Java 25
Browsers
Chrome 153 (Windows 11). Also reproduced in headless Chrome.
- Lenguaje dominante
- TypeScript
- Estrellas
- 18
- Forks
- 4
- Merge medio
- 51 min
- PR fusionados (30 d)
- 8
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 vaadin/react-components
-
bug Impact: Low Severity: Major
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
vaadin/react-components#398 · 1 comentario ·
-
Add Vertical mode in TabSheetAbiertoenhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
vaadin/react-components#338 · 1 reacción ·
-
hilla react
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
vaadin/react-components#337 · 8 comentarios ·
-
bug Impact: Low Severity: Major
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
vaadin/react-components#323 ·
-
bug Impact: Low Severity: Minor
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
vaadin/react-components#322 ·
Todos los issues de vaadin/react-components
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
chaitin/MonkeyCode#1437 ·
Los mantenedores suelen responder en 1 día
-
rtdb-info-connected-order test: unhandled 'connection is closed' rejection fails the CLI suiteAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
carbon-design-system/carbon-ai-chat#2615 ·
Los mantenedores suelen responder en 1 día
-
e2e-failure ready-to-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
redhat-developer/rhdh-plugin-export-overlays#4486 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: fileUploadMatrix.test.ts URL case does a real DNS lookup and fails offlinePosiblemente ocupada @r2jaff la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ComposioHQ/composio#5054 ·
Los mantenedores suelen responder en 1 día