Skip to content

[Web] With semantics enabled, a click inside a TextFieldTapRegion stops typing in the focused TextField #195291

Open

Description

@nogringo

Steps to reproduce

  1. Run the sample below with flutter run -d chrome.
  2. The field has the focus. Type a few characters.
  3. Click "Click this text".
  4. Type again.

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 the click appear in the field. The text is in the field's tap region, so the field keeps the focus, as it does for a formatting toolbar.

Actual results

The field keeps the focus in the framework, and its caret keeps blinking, but nothing typed after the click appears. document.activeElement is the flutter-view element.

Clicking a part of the tap region that has no semantics node, such as empty space in a Container, does not break typing.

What I think happens: the mouse press on the text's semantics element moves the browser focus to its nearest focusable ancestor, the flutter-view element. With semantics enabled, the field types into the <input> of its SemanticTextField, whose blur listener calls SemanticsTextEditingStrategy.deactivate. Nothing activates it again, because the framework focus never changed. With semantics disabled, the default editing strategy handles the same blur by focusing its <input> again.

Workaround: keep the browser from moving the focus.

// Called once at startup, on the web only.
web.EventStreamProviders.mouseDownEvent
    .forTarget(web.document, useCapture: true)
    .listen((event) {
  final active = web.document.activeElement;
  if (active?.getAttribute('data-semantics-role') != 'text-field') return;
  final target = event.target as web.Element;
  if (target.getAttribute('data-semantics-role') == 'text-field') return;
  if (target.closest('flt-semantics') != null) event.preventDefault();
});

Code sample

Code sample
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: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // Part of the text field's tap region, like a formatting toolbar.
              TextFieldTapRegion(child: Text('Click this text')),
              TextField(autofocus: true),
            ],
          ),
        ),
      ),
    ),
  );
}

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

  1. added
    in triage
    a: text input
    a: accessibility
    has reproducible steps
    fyi-web
    team-accessibility
    and removed
    in triage
    on Oct 26, 2026
  2. mbcorona commented on Oct 26, 2026

    @mbcorona
    Member

    Hi @nogringo, thanks for the report.
    Same area as #195289 and #195290.

    Routing to team-accessibility.

  3. flutter-zl commented on Oct 28, 2026

    @flutter-zl
    Contributor
    Reproduced on Chrome with a recent master build.
    
    Demo: https://flutter-demo-84-before.web.app
    
    1. The field has focus. Type a few characters.
    2. Click "Click this text".
    3. Type again.
    
    After the click, `document.activeElement` is `FLUTTER-VIEW`, `FocusNode.hasFocus` stays true, and nothing typed afterwards reaches `controller.text`. Clicking the grey box, which is also inside the tap
    region but has no semantics node, does not break typing.
    
    Same area as #195289 and #195290: the semantics `<input>` loses browser focus while the framework still considers the field focused.
    
  4. added
    triaged-web
    P2
    on Oct 28, 2026
  5. removed
    fyi-web
    triaged-web
    on Oct 28, 2026
  6. added
    team-web
    triaged-web
    and removed
    team-accessibility
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: accessibilitya: text inputhas reproducible stepsteam-webtriaged-web

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions