Skip to content

Read-only TextField prevents focus from changing #161482

Closed

Description

@Pante

Steps to reproduce

  • Build the application for MacOS.
  • Press tab three times.

Expected results

The focus should be on the 3rd textfield.

Actual results

The focus is still on the 2nd textfield which is readOnly.

Code sample

Code sample
void main() => runApp(const Foo());

class Foo extends StatelessWidget {
  const Foo({super.key});

  @override
  Widget build(BuildContext context) => const MaterialApp(
    home: Scaffold(
      body: Column(
        children: [
          TextField(),
          TextField(readOnly: true),
          TextField(),
        ],
      ),
    ),
  );
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.2 24C101 darwin-arm64, locale en-SG)
    • Flutter version 3.27.1 on channel stable at /Users/matthias/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (4 weeks ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/matthias/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Users/matthias/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Users/matthias/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.4+-12422083-b607.1)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.3.1.1)
    • IntelliJ at /Users/matthias/Applications/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 83.0.4
    • Dart plugin version 243.23177

[✓] Connected device (4 available)
    • Overpriced Phone (mobile)       • 00008030-0009195E1E41802E • ios            • iOS 18.1.1 22B91
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 15.2 24C101 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 15.2 24C101 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 131.0.6778.265

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

Activity

  1. raslan1994 commented on Jan 12, 2025

    @raslan1994

    In order to skip the node from focus traversal policy, you can use FocusNode(skipTraversal: true) for that specific TextField

    example:

    TextField(
      focusNode: FocusNode(skipTraversal: true),
      readOnly: true,
      decoration: InputDecoration(labelText: 'Readonly TextField'),
    ),

    As per your code sample you can do the alteration as follows,

    class Foo extends StatelessWidget {
      const Foo({super.key});
    
      @override
      Widget build(BuildContext context) => MaterialApp(
            home: Scaffold(
              body: SafeArea(
                child: Column(
                  children: [
                    TextField(
                      decoration: InputDecoration(labelText: 'Editable TextField'),
                    ),
                    TextField(
                      focusNode: FocusNode(skipTraversal: true),
                      readOnly: true,
                      decoration: InputDecoration(labelText: 'Readonly TextField'),
                    ),
                    TextField(
                      decoration:
                          InputDecoration(labelText: 'Another Editable TextField'),
                    ),
                  ],
                ),
              ),
            ),
          );
    }
  2. Pante commented on Jan 12, 2025

    @Pante
    ContributorAuthor

    I don't think that solution is ideal as it skips the TextField entirely.

  3. added
    in triagePresently being triaged by the triage team
    on Jan 13, 2025
  4. huycozy commented on Jan 13, 2025

    @huycozy
    Member

    Reproduced the issue on Flutter master channel 3.28.0-2.0.pre.38699 as well. Also marking this has a workaround as mentioned above.Thanks!

  5. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: focusFocus traversal, gaining or losing focus
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    workaround availableThere is a workaround available to overcome the issue
    and removed
    in triagePresently being triaged by the triage team
    on Jan 13, 2025
  6. Pante commented on Jan 13, 2025

    @Pante
    ContributorAuthor

    @huycozy I don't believe the workaround is desirable. In my mind, the focus should move to the read-only textfield, then the next focus item, rather than skipping the read-only textfield entirely.

  7. added
    P2Important issues not at the top of the work list
    on Jan 16, 2025
  8. justinmc commented on Jan 16, 2025

    @justinmc
    Contributor

    @Pante Can you break down where the focus goes each time you press the tab key and where you expect it to go?

  9. Pante commented on Jan 17, 2025

    @Pante
    ContributorAuthor

    Given the following code snippet:

    void main() => runApp(const Foo());
    
    class Foo extends StatelessWidget {
      const Foo({super.key});
    
      @override
      Widget build(BuildContext context) => const MaterialApp(
        home: Scaffold(
          body: Column(
            children: [
              TextField(),
              TextField(readOnly: true),
              TextField(),
            ],
          ),
        ),
      );
    }

    Assuming that I'm focused on the first text-field, the current implementation shifts to the 2nd textfield unlike the proposed workaround which shifts to the 3rd textfield. This is expected behavior.

    When focused on the 2nd textfield, the current implementation retains the focus on the 2nd textfield regardless of how many times I press tab. I expect the focus to shift to the 3rd textfield when I press tab once.

  10. self-assigned this
    on Mar 25, 2025
  11. moved this from To do to In progress in Nevercodeon Mar 26, 2025
  12. moved this from In progress to Done (PR merged) in Nevercodeon Apr 3, 2025
  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Apr 3, 2025
  14. github-actions commented on Apr 17, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsf: focusFocus traversal, gaining or losing focusfound in release: 3.27Found to occur in 3.27found in release: 3.28Found to occur in 3.28frameworkflutter/packages/flutter repository. See also f: labels.has 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 teamworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

  • Status
    Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions