Repository navigation
Closed
flutter/packages
#13179Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.22Found to occur in 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24Found to occur in 3.24has 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/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Steps to reproduce
- Run the code sample
- Make sure the dropdown field is editable
- Press the "Disable" button and then the "Enable" one
- Try to edit the field again
Expected results
The mouse cursor should be of the tipe 'text' and the widget's field should be editable like it was in the initial state.
Actual results
The mouse cursor is of the tipe 'click' and the widget's field is not editable anymore.
Code sample
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const DropdownMenuExample());
}
enum ColorLabel {
blue('Blue', Colors.blue),
pink('Pink', Colors.pink),
green('Green', Colors.green),
yellow('Orange', Colors.orange),
grey('Grey', Colors.grey);
const ColorLabel(this.label, this.color);
final String label;
final Color color;
}
class DropdownMenuExample extends StatefulWidget {
const DropdownMenuExample({super.key});
@override
State<DropdownMenuExample> createState() => _DropdownMenuExampleState();
}
class _DropdownMenuExampleState extends State<DropdownMenuExample> {
final TextEditingController colorController = TextEditingController();
final FocusNode focusNode = FocusNode();
ColorLabel? selectedColor;
bool isEnabled = true;
@override
void dispose() {
colorController.dispose();
focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.green,
),
home: Scaffold(
body: SafeArea(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
DropdownMenu<ColorLabel>(
enabled: isEnabled,
initialSelection: ColorLabel.green,
controller: colorController,
focusNode: focusNode,
label: const Text('Color'),
onSelected: (ColorLabel? color) {
setState(() {
selectedColor = color;
});
},
dropdownMenuEntries: ColorLabel.values
.map<DropdownMenuEntry<ColorLabel>>(
(ColorLabel color) {
return DropdownMenuEntry<ColorLabel>(
value: color,
label: color.label,
style: MenuItemButton.styleFrom(
foregroundColor: color.color,
),
);
}).toList(),
),
const SizedBox(width: 24),
FilledButton(
onPressed: () {
setState(() {
isEnabled = !isEnabled;
});
},
child: Text(
!isEnabled ? 'Enable' : 'Disable',
),
),
],
),
),
],
),
),
),
);
}
}
Screenshots or Video
Screenshots / Video demonstration
Screen.Recording.2024-07-29.at.11.06.43.mov
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.22.3, on macOS 13.5 22G74 darwin-arm64, locale en-US) ✔ 17s
• Flutter version 3.22.3 on channel stable at /Users/parsodyl/.puro/envs/stable/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b0850beeb2 (12 days ago), 2024-07-16 21:43:41 -0700
• Engine revision 235db911ba
• Dart version 3.4.4
• DevTools version 2.34.3
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/parsodyl/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Users/parsodyl/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A240d
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Users/parsodyl/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 17.0.6+0-17.0.6b829.9-10027231)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.2)
• IntelliJ at /Users/parsodyl/Applications/IntelliJ IDEA Ultimate.app
• Flutter plugin version 76.3.4
• Dart plugin version 232.9559.10
[✓] Connected device (4 available)
• iPhone SE (3rd generation) (mobile) • CB910630-CE1E-4F4D-9A2D-C6A6B502A7CB • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.5 22G74 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 13.5 22G74 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.185
[✓] Network resources
• All expected network resources are available.
• No issues found!
Reacted by Abid Shaon, r-durao-pvotal, Alberto Miola and MiniSuperDev
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: focusFocus traversal, gaining or losing focusFocus traversal, gaining or losing focusfound in release: 3.22Found to occur in 3.22Found to occur in 3.22found in release: 3.24Found to occur in 3.24Found to occur in 3.24has 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/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
[-][DropdownMenuEntry] providing a `focusNode`, the text cursor is lost after disabling the widget and enabling it again[/-][+][DropdownMenu] providing a `focusNode`, the text cursor is lost after disabling the widget and enabling it again[/+]danagbemava-nc commentedon Jul 29, 2024
Reproducible using the code sample provided above.
It works as expected if the
focusNodeis not set for theDropdownMenu.flutter doctor -v
PurplePolyhedron commentedon Jul 29, 2024
It seems the
focusNode.canRequestFocusis set to false by something when the widget is disabled.Possible workaround by manually setting it to true when re-enable the widget.
d-paradiso-pvotal commentedon Jul 30, 2024
@PurplePolyhedron thanks for the workaround.
It seems that the
TextField(on every widget update) basically does this:focusNode.canRequestFocus = canRequestFocus && enabled.But following the code in the
DropdownMenu, we have thatTextField.canRequestFocusalready depends onfocusNode.canRequestFocus.Keeping the default value (true) for
TextField.canRequestFocuswhen afocusNodeis provided might resolve the issue.[material_ui] Fix DropdownMenu losing text cursor when re-enabled (fl…