mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fixes [[DropdownMenu] Semantics still reads out "EditBox" when text editing is disabled](https://github.com/flutter/flutter/issues/151686) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart 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> { ColorLabel? selectedColor; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: SafeArea( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, spacing: 16.0, children: <Widget>[ const ExcludeSemantics(child: Text('TexField')), const TextField( readOnly: true, decoration: InputDecoration( labelText: 'Color', border: OutlineInputBorder(), ), ), const ExcludeSemantics(child: Text('DropdownMenu')), DropdownMenu<ColorLabel>( requestFocusOnTap: false, label: const Text('Color'), dropdownMenuEntries: ColorLabel.values .map<DropdownMenuEntry<ColorLabel>>((ColorLabel color) { return DropdownMenuEntry<ColorLabel>( value: color, label: color.label, style: MenuItemButton.styleFrom( foregroundColor: color.color, ), ); }).toList(), ), ], ), ), ), ), ); } } ``` </details> ### Preview (with Talkback captions) |Before | After | | --------------- | --------------- | | <img src="https://github.com/user-attachments/assets/0d9f79f3-de5d-4c42-adea-3d700464d001" /> | <img src="https://github.com/user-attachments/assets/cf38508e-61f7-43ff-b420-ffe24cc8e28f" /> | ### Before demo DropdownMenu announces "EditBox" and "double tap to activate" when setting `DropdownMenu.requestFocusOnTap` to `false` shouldn't allow that https://github.com/user-attachments/assets/f692a4f6-9d6a-4834-8df0-baf6c65fae29 ### After demo When setting `DropdownMenu.requestFocusOnTap` to `false`, the underlying `TextField` gets read only state which changes the semantics to be not editable or focusable and remove"EditBox" and "double tap to activate" announcments https://github.com/user-attachments/assets/0e14a636-6b81-4535-a5d1-c8f301c4f89e
Flutter
Flutter is a new way to build high-performance, cross-platform mobile, web, and desktop apps. Flutter is optimized for today's — and tomorrow's — mobile and desktop devices. We are focused on low-latency input and high frame rates on all platforms.
See the getting started guide for information about using Flutter.