`autofocus` prop has no effect on initial render in React components (e.g. `<TextField autofocus />`)
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 18
- Forks
- 4
- Avg merge
- 44m
- Merged PRs (30d)
- 9
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vaadin/react-components
-
bug Impact: Low Severity: Major
Difficulty 4/5 3-5 days Newbie friendliness 48/100
vaadin/react-components#398 · 1 comment ·
-
enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
vaadin/react-components#338 · 1 reaction ·
-
hilla react
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
vaadin/react-components#337 · 8 comments ·
-
bug Impact: Low Severity: Major
Difficulty 3/5 1-2 days Newbie friendliness 50/100
vaadin/react-components#323 ·
-
bug Impact: Low Severity: Minor
Difficulty 3/5 1-2 days Newbie friendliness 45/100
vaadin/react-components#322 ·
All issues in vaadin/react-components
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
farbenmeer/tapi#531 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
naver/egjs-flicking#971 ·
-
Renderer treats a sub-pixel width difference as a resize, which cancels the `motion()` entranceOpen
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Tenant
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
MTES-MCT/Dossier-Facile-Frontend#2061 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
backnotprop/plannotator#1784 ·
Maintainers usually reply within 1 day