Repository navigation
Description
Steps to reproduce
- Run the sample below with
flutter run -d chrome. - The field has the focus. Type a few characters within 5 seconds.
- After 5 seconds, keep typing.
The sample calls SemanticsBinding.instance.ensureSemantics(). Without that line, everything works. An app without it gets the same bug as soon as a user activates Flutter web's hidden "Enable accessibility" button.
Expected results
The characters typed after 5 seconds appear in the field.
Actual results
When the sample inserts a semantics node above the field, the field loses the focus: its FocusNode.hasFocus turns false, document.activeElement is <body>, and nothing typed afterwards appears.
In a real app, a Tooltip is enough to trigger it. On a page pushed on a go_router ShellRoute navigator, the route's semantics node is merged into the navigator's node while it has no sibling. Hovering an IconButton with a tooltip adds the tooltip's node as a sibling, the route's node is created above the page, and the focused field of that page loses the focus. The sample replaces that setup with a Semantics(container:) that turns on after 5 seconds.
What I think happens: SemanticsObject.updateChildren moves the DOM element of the field's existing ancestor into the new node with append or insertBefore. Moving a focused element in the DOM blurs it with no relatedTarget, and the focus lands on <body>. ViewFocusBinding then reports the view as unfocused, and View parks the focus on the root scope.
Workaround: restore the focus before the engine sees the blur.
// Called once at startup, on the web only.
for (final type in ['blur', 'focusout']) {
web.EventStreamProvider<web.FocusEvent>(type)
.forTarget(web.window, useCapture: true)
.listen((event) {
final field = event.target as web.HTMLElement;
if (field.getAttribute('data-semantics-role') != 'text-field') return;
if (event.relatedTarget != null ||
!web.document.hasFocus() ||
!field.isConnected) {
return;
}
event.stopImmediatePropagation();
scheduleMicrotask(
() => field.focus(web.FocusOptions(preventScroll: true)),
);
});
}Code sample
Code sample
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SemanticsBinding.instance.ensureSemantics();
runApp(
const MaterialApp(
home: Scaffold(
body: Padding(padding: EdgeInsets.all(24), child: Sample()),
),
),
);
}
class Sample extends StatefulWidget {
const Sample({super.key});
@override
State<Sample> createState() => _SampleState();
}
class _SampleState extends State<Sample> {
bool _container = false;
@override
void initState() {
super.initState();
// Inserts a semantics node above the field, as a tooltip showing can.
Timer(const Duration(seconds: 5), () => setState(() => _container = true));
}
@override
Widget build(BuildContext context) {
return Semantics(
container: _container,
explicitChildNodes: true,
child: const TextField(
autofocus: true,
decoration: InputDecoration(hintText: 'Keep typing'),
),
);
}
}Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.47.7, on macOS 27.0.1 26A434 darwin-arm64, locale en-US)
• Flutter version 3.47.7 on channel stable at /Users/gringo/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision abaf9c5237 (2 weeks ago), 2026-10-08 09:51:21 -0700
• Engine revision deb287481e
• Dart version 3.13.5
• DevTools version 2.60.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 27.0.1 26A434 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 155.0.8059.85
Activity
suryaKommana2662 commentedon Oct 26, 2026
@nogringo Thanks for the report. I was able to reproduce the issue on Flutter Web using Chrome. After the semantics node is inserted above the focused TextField, the field loses focus. Routing this to the accessibility team for further investigation.
flutter-zl commentedon Oct 28, 2026
flutter-triage-bot commentedon Oct 28, 2026
The
triaged-weblabel is irrelevant if there is noteam-weblabel orfyi-weblabel.flutter-triage-bot commentedon Oct 28, 2026
Issue is assigned to multiple teams (web, accessibility). Please ensure the issue has only one
team-*label at a time. Usefyi-*labels to have another team look at the issue without reassigning it.