Skip to content

[TextField] When switching to another browser tab or window and then going back, all text on TextField is selected automatically #156078

@ThHareau

Description

@ThHareau

Steps to reproduce

Could work with any text field as far as I know. Here is a dart pad : https://dartpad.dev/?id=c1df1f23d5be833eb2f45004a2c37d63&channel=main

  1. ensure the field is focused (by clicking on it)
  2. switch tab or window
  3. go back to the demo tab

The whole text field content is now selected.

Expected results

The cursor stays at the same position as before, or at least not all the text is selected

Actual results

all the text is selected, leading to accidental text deletion

Code sample

Code sample
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: TextField(
          autofocus: true,
          controller: TextEditingController(
            text: 'Some text I do not people to accidentally delete',
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
Capture.video.du.2024-10-02.15-21-07.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.22.2, on Fedora Linux 40 (Workstation Edition)
    6.10.11-200.fc40.x86_64, locale fr_FR.UTF-8)
    • Flutter version 3.22.2 on channel stable at
      /home/thareau/Logiciels/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 761747bfc5 (il y a 4 mois), 2024-06-05 22:15:13 +0200
    • Engine revision edd8546116
    • Dart version 3.4.3
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /home/thareau/Logiciels/AndroidSdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (Red_Hat-17.0.12.0.7-2) (build
      17.0.12+7)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at
    google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✗] Linux toolchain - develop for Linux desktop
    ✗ clang++ is required for Linux development.
      It is likely available from your distribution (e.g.: apt install clang),
      or can be downloaded from https://releases.llvm.org/
    ✗ CMake is required for Linux development.
      It is likely available from your distribution (e.g.: apt install cmake),
      or can be downloaded from https://cmake.org/download/
    ✗ ninja is required for Linux development.
      It is likely available from your distribution (e.g.: apt install
      ninja-build), or can be downloaded from
      https://github.com/ninja-build/ninja/releases
    • pkg-config version 2.1.1
    ✗ GTK 3.0 development libraries are required for Linux development.
      They are likely available from your distribution (e.g.: apt install
      libgtk-3-dev)

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup
      for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2024.2)
    • IntelliJ at
      /home/thareau/.local/share/JetBrains/Toolbox/apps/intellij-idea-ultimate
    • Flutter plugin version 81.1.3
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Fedora Linux 40 (Workstation
      Edition) 6.10.11-200.fc40.x86_64

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsfound in release: 3.24Found to occur in 3.24found in release: 3.26Found to occur in 3.26has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-text-inputOwned by Text Input teamtriaged-text-inputTriaged by Text Input team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions