Repository navigation
TextField's onTapOutside is triggered even if textfield wasn't focused #134341
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Add two text fields in a column
- For one of them, add a onTapOutside callback with a debug print.
- For the second one, do nothing
- Click inside the textfield that does not have the onTapOutside defined
- Click anwhere outside of the textfield
Expected results
The callback should only be invoke only if the textfield had been focused before.
The comment of the callback states:
Called for each tap that occurs outside of the[TextFieldTapRegion] group when the text field is focused.
Actual results
The callback of the first textfield is called
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
actions: [],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
key: const ValueKey("1"),
decoration: const InputDecoration(
hintText: "1",
),
onTapOutside: (event) {
debugPrint("Callback from 1");
},
),
const TextField(
key: ValueKey("2"),
decoration: InputDecoration(
hintText: "2",
),
),
],
),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
Callback from 1Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.13.3, on macOS 13.5.1 22G90 darwin-arm64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] VS Code (version 1.81.1)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
Mairramer commentedon Sep 9, 2023
I tested it here and even passing the focus it still executes
danagbemava-nc commentedon Sep 11, 2023
Reproducible using the code sample provided above.
flutter doctor -v
Mairramer commentedon Sep 17, 2023
Hi @burakmartin , the onTapOutside is always triggered inside
TextFieldTapRegionby default. To avoids regression, this setting remains the same. However, we now offer the option to disable it if necessary.[-]TextField's onTapOutside is triggered even if textfield wasnt focused[/-][+]TextField's onTapOutside is triggered even if textfield wasn't focused[/+]fix:: trigger onTapOutside only if has focus (#136291)
Renzo-Olivares commentedon Nov 30, 2023
Hi @burakmartin, the default behavior was updated to match the documentation in #136291. Per that pr I will close this issue. Feel free to re-open if the issue has not been resolved.
github-actions commentedon Dec 15, 2023
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 -vand a minimal reproduction of the issue.