Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Web] showTimePicker should highlight minutes when pressing the TAB button in the hours field #165830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
geronimol opened this issue Mar 24, 2025 · 10 comments
Assignees
Labels
a: text input Entering text in a text field or keyboard related problems f: date/time picker Date or time picker widgets framework flutter/packages/flutter repository. See also f: labels. fyi-text-input For the attention of Text Input team P1 High-priority issues at the top of the work list platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version team-web Owned by Web platform team triaged-web Triaged by Web platform team

Comments

@geronimol
Copy link

Steps to reproduce

  1. Run the sample code for Web.
  2. Click the button, which opens the time picker.
  3. Click the hours field and then TAB to switch to the minutes field.

Expected results

Minutes field highlighted in the same way as when you TAB from one to another TextField.

Actual results

Minutes field focusing at the end of the minutes, without highlighting them.

Code sample

Code sample
ElevatedButton(
  onPressed: () => showTimePicker(
    context: context,
    initialTime: TimeOfDay.now(),
    initialEntryMode: TimePickerEntryMode.inputOnly,
  ),
  child: Text('Test'),
),

Screenshots or Video

Screenshots / Video demonstration
2025-03-24.16-47-47.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.2, on macOS 15.3.2 24D81 darwin-x64, locale es-419) [3.5s]
    • Flutter version 3.29.2 on channel stable at /Users/gero/fvm/versions/3.29.2
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c236373904 (11 days ago), 2025-03-13 16:17:06 -0400
    • Engine revision 18b71d647a
    • Dart version 3.7.2
    • DevTools version 2.42.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [8.6s]
    • Android SDK at /Users/gero/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2024.3) [43ms]
    • Android Studio at /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.5+-12932927-b750.29)

[✓] Android Studio (version 2024.2) [40ms]
    • Android Studio at /Volumes/Latest/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.3+-79915915-b509.11)

[✓] VS Code (version 1.96.4) [37ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available) [12.3s]
    • macOS (desktop) • macos  • darwin-x64     • macOS 15.3.2 24D81 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 134.0.6998.118

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

• No issues found!
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Mar 25, 2025
@darshankawar
Copy link
Member

@geronimol
I tried the same with latest master version running on web and observed the expected behavior, ie the minutes field is highlighted in the same way as hours field. I didn't notice any difference. I also verified on macOS desktop platform and it was same.
Can you try the same as your end ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 25, 2025
@geronimol
Copy link
Author

geronimol commented Mar 25, 2025

@darshankawar Just tested with the latest master version and isn't working as expected.

Note: Text should be completely highlighted, so it should be removed when you press the backspace button once(not twice). Basically the same behavior as when you jump from one TextField with text to another using TAB.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 25, 2025
@darshankawar
Copy link
Member

@geronimol
Can you check and confirm what is the native behavior for this (iOS or android or even desktop) ? Because I am not sure if this is a bug.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 26, 2025
@geronimol
Copy link
Author

@darshankawar I am not sure if this is a bug either. But I thought these fields were supposed to behave the same way as a TextField in web.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 26, 2025
@darshankawar
Copy link
Member

@geronimol
I am not completely sure or understood the issue here, as per my verification, the tab worked properly consistently in all platforms in flutter (web, desktop and mobile), so it seems to be WAI.
I suggest you to check in native apps (non flutter) to see how it behaves and if it is different from flutter, then we can probably consider this to implement in flutter.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 27, 2025
@geronimol
Copy link
Author

@darshankawar Please check what happens in the example below when you have focused the first TextFieldand you press the Tab button.

class FocusTest extends StatefulWidget {
  const FocusTest({super.key});

  @override
  State<FocusTest> createState() => _FocusTestState();
}

class _FocusTestState extends State<FocusTest> {
  TextEditingController controller1 = TextEditingController(), controller2 = TextEditingController();

  @override
  void initState() {
    super.initState();
    controller1.text = '12';
    controller2.text = '00';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            TextFormField(controller: controller1),
            TextFormField(controller: controller2),
          ],
        ),
      ),
    );
  }
}
2025-03-27.14-15-43.mov

As you can see, the "00" text is completely highlighted. Should the picker fields work the same way?

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 27, 2025
@darshankawar
Copy link
Member

I'll keep the issue open for team's tracking for expected behavior or this is something need to be fixed or not.

@darshankawar darshankawar added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: date/time picker Date or time picker widgets team-text-input Owned by Text Input team and removed in triage Presently being triaged by the triage team labels Mar 28, 2025
@justinmc justinmc added team-web Owned by Web platform team fyi-text-input For the attention of Text Input team and removed team-text-input Owned by Text Input team labels Apr 3, 2025
@justinmc
Copy link
Contributor

justinmc commented Apr 3, 2025

I added this to team-web as it seems to only happen there, but it also was not fully reproducible. Let me know if it would be better for text-input to take this.

@yjbanov yjbanov added platform-web Web applications specifically P2 Important issues not at the top of the work list triaged-web Triaged by Web platform team labels Apr 9, 2025
@flutter-zl flutter-zl self-assigned this Apr 24, 2025
@Renzo-Olivares
Copy link
Contributor

@darshankawar Please check what happens in the example below when you have focused the first TextFieldand you press the Tab button.

class FocusTest extends StatefulWidget {
const FocusTest({super.key});

@OverRide
State createState() => _FocusTestState();
}

class _FocusTestState extends State {
TextEditingController controller1 = TextEditingController(), controller2 = TextEditingController();

@OverRide
void initState() {
super.initState();
controller1.text = '12';
controller2.text = '00';
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
TextFormField(controller: controller1),
TextFormField(controller: controller2),
],
),
),
);
}
}
2025-03-27.14-15-43.mov
As you can see, the "00" text is completely highlighted. Should the picker fields work the same way?

The reason the time picker field doesn't behave the same way is because it's field has maxLines: null and expands: true so that the field expands to the full height of its parent container. maxLines: null implies the field is multi-line, and tabbing to select all is disabled for multi-line fields.

@mdebbar mdebbar removed the P2 Important issues not at the top of the work list label Apr 30, 2025
@mdebbar mdebbar added the P1 High-priority issues at the top of the work list label Apr 30, 2025
github-merge-queue bot pushed a commit that referenced this issue May 2, 2025
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

This PR addresses the issue in time_picker.dart where pressing the TAB
key to navigate between the hour and minute fields in input mode doesn't
properly select the text in the newly focused field.

**What Changed**

- Added focus traversal logic in the _HourMinuteTextFieldState class's
initState method that:

1. Properly handles TAB key presses to move focus to the next field
2. Automatically selects all text when a field gains focus

- Added tests in time_picker_test.dart to verify that:

1. The hour field's text is selected when it gains focus
2. Pressing TAB moves focus to the minute field
3. The minute field's text is selected when it receives focus via TAB
key

**Why This Matters**
This change improves accessibility and usability of the time picker in
input mode. When users navigate using the keyboard (pressing TAB), they
expect the text in the newly focused field to be fully selected,
allowing them to immediately type a new value without having to manually
delete the existing text. This is standard behavior in form fields and
now the TimePicker component follows this expected pattern.

**Before the change:**
web:
https://time-picker-0423-before-change.web.app/
mobile:

https://github.com/user-attachments/assets/532c8aa2-4f8d-4118-9eaa-2fc6c2825486


**After the change:**
web:
https://time-picker-04232025.web.app/
mobile:

https://github.com/user-attachments/assets/9271b3b0-9ece-479e-a01e-a62e31b1d6c7



**Issue to fix:** 
#165830 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
@bleroux
Copy link
Contributor

bleroux commented May 6, 2025

Closing as fixed, see #167766

@bleroux bleroux closed this as completed May 6, 2025
@bleroux bleroux added the r: fixed Issue is closed as already fixed in a newer version label May 6, 2025
mboetger pushed a commit to mboetger/flutter that referenced this issue May 6, 2025
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

This PR addresses the issue in time_picker.dart where pressing the TAB
key to navigate between the hour and minute fields in input mode doesn't
properly select the text in the newly focused field.

**What Changed**

- Added focus traversal logic in the _HourMinuteTextFieldState class's
initState method that:

1. Properly handles TAB key presses to move focus to the next field
2. Automatically selects all text when a field gains focus

- Added tests in time_picker_test.dart to verify that:

1. The hour field's text is selected when it gains focus
2. Pressing TAB moves focus to the minute field
3. The minute field's text is selected when it receives focus via TAB
key

**Why This Matters**
This change improves accessibility and usability of the time picker in
input mode. When users navigate using the keyboard (pressing TAB), they
expect the text in the newly focused field to be fully selected,
allowing them to immediately type a new value without having to manually
delete the existing text. This is standard behavior in form fields and
now the TimePicker component follows this expected pattern.

**Before the change:**
web:
https://time-picker-0423-before-change.web.app/
mobile:

https://github.com/user-attachments/assets/532c8aa2-4f8d-4118-9eaa-2fc6c2825486


**After the change:**
web:
https://time-picker-04232025.web.app/
mobile:

https://github.com/user-attachments/assets/9271b3b0-9ece-479e-a01e-a62e31b1d6c7



**Issue to fix:** 
flutter#165830 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems f: date/time picker Date or time picker widgets framework flutter/packages/flutter repository. See also f: labels. fyi-text-input For the attention of Text Input team P1 High-priority issues at the top of the work list platform-web Web applications specifically r: fixed Issue is closed as already fixed in a newer version team-web Owned by Web platform team triaged-web Triaged by Web platform team
Projects
None yet
Development

No branches or pull requests

8 participants