Skip to content

[Proposal] Allow possibility to maintain focus on TextField #92541

Closed

Description

@YowFung

Use case

See #92079.

Proposal

Allow the possibility to maintain focus on a TextField.
It should be disabled by default according to the material design specification but can be enabled through a property.

Note:

If this is already possible, kindly point me to the documentation or a working example.
Thank you


/cc @danagbemava-nc

Activity

  1. changed the title [-]Is there a possibility that we can choose whether or not we want to keep the focus on TextField?[/-] [+][Proposal] Allow possibility to maintain focus on TextField[/+] on Oct 27, 2021
  2. added
    a: text inputEntering text in a text field or keyboard related problems
    f: focusFocus traversal, gaining or losing focus
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    and removed
    in triagePresently being triaged by the triage team
    on Oct 27, 2021
  3. HansMuller commented on Oct 27, 2021

    @HansMuller
    Contributor
  4. YowFung commented on Mar 9, 2022

    @YowFung
    Author

    @HansMuller @darshankawar
    I found that the TextField widget can keep its focus status now. Has this proposal been passed? If so, can you tell me which parameter can control this status?

  5. HansMuller commented on Mar 9, 2022

    @HansMuller
    Contributor

    @justinmc, @gspencergoog - was the regression reported in #92079 fixed?

  6. gspencergoog commented on Mar 9, 2022

    @gspencergoog
    Contributor

    @HansMuller Do you mean the cursor height regression?

    I found that the TextField widget can keep its focus status now.

    Unless I missed something that has changed, this is probably a regression: the focus should be removed from the text field when clicking outside of it. @justinmc has anything changed with FocusTrap?

  7. justinmc commented on Mar 9, 2022

    @justinmc
    Contributor

    This is a valid issue (kind of overlapping with #86972, but I think it's ok to keep this open). Here's the current situation.

    Desired behavior

    • On web, tapping on a blank area outside of a text field should remove the focus. Tabbing from there should resume the tab order at the beginning.
    • On all non-web platforms, tapping on a blank area should not remove focus.
    • On all platforms, it should be possible to build a button that does not steal the focus from a text field when tapped.

    Current Flutter behavior

    • On all platforms except mobile, tapping on a blank area removes focus from a text field.
      • This includes mobile web, incorrectly.
    • It's not possible to build a button that doesn't steal focus due to how FocusTrap works.

    How can we fix this?

    We need to refactor FocusTrap. I made an attempt at that (#99434), but I ran into test failures due to overlapping gesture detectors, and I haven't been able to figure out a way to fix it. I hope to come back to it, but if anyone else has a solution it would be most welcome!

  8. justinmc commented on Mar 9, 2022

    @justinmc
    Contributor

    I've put up a small partial fix (just the platform behavior): #99849. It will still not be possible to build a button that doesn't steal focus on web, unfortunately.

  9. YowFung commented on Mar 10, 2022

    @YowFung
    Author

    Current Flutter behavior

    • On all platforms except mobile, tapping on a blank area removes focus from a text field.
      • This includes mobile web, incorrectly.
    • It's not possible to build a button that doesn't steal focus due to how FocusTrap works.

    My current situation:

    • Using flutter version 2.10.3 stable.
    • On the macOS platform.
    • Tapping on a blank area doesn't remove focus from a TextField.

    My desired behavior:

    • The TextField has a parameter that can control the focus behavior(keep or remove focus when clicking outside of it).
  10. creativecreatorormaybenot commented on Apr 25, 2022

    @creativecreatorormaybenot
    Contributor

    It's not possible to build a button that doesn't steal focus due to how FocusTrap works.

    This applies to all platforms, right? @justinmc

    That would basically mean it is impossible to build the following behavior in Flutter, i.e. the keyboard staying open when tapping to record a voice message (e.g. Instagram):

    RPReplay_Final1650899053.mov

    At least from what I tried, I could not make it work. In whatever way I setup the widgets, the keyboard always closes when tapping the record button.

  11. gspencergoog commented on Aug 1, 2022

    @gspencergoog
    Contributor

    This should now be possible using the TextFieldTapRegion widget to indicate that a control is considered part of the same tap region group as the text field. See the PR: #107262

  12. added
    r: fixedIssue is closed as already fixed in a newer version
    on Aug 2, 2022
  13. github-actions commented on Aug 16, 2022

    @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.

  14. locked as resolved and limited conversation to collaborators on Aug 16, 2022
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

    a: text inputEntering text in a text field or keyboard related problemsc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterf: focusFocus traversal, gaining or losing focusframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions