flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.59k stars 27.34k forks source link

[web][a11y] `autofocus` causes Safari to lose semantics #107595

Open vsomayaji opened 2 years ago

vsomayaji commented 2 years ago

Steps to Reproduce

  1. Execute flutter run -d chrome on the code sample.
  2. Open the application in Safari and enable VoiceOver.
  3. Use VO + Space to click the Page 2 button.
  4. Use VO + Space to click the Page 1 button.
  5. Try and use VO + Space to click the Page 2 button or to check the Check me checkbox.

Expected results:

The semantics of the Page 2 button and the Check me checkbox should be preserved and the screen reader should be able to interact with the elements.

Actual results:

The semantics are lost and the screen reader reads the elements as groups (see the attached video). Setting autofocus: false on the first button resolves this issue.

Code sample ```dart import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); // Auto-enable accessibility for our Blind and Low Vision customers (see // https://docs.flutter.dev/development/accessibility-and-localization/accessibility#screen-readers). RendererBinding.instance.setSemanticsEnabled(true); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Safari A11y Issue', initialRoute: Page1.routeName, routes: { Page1.routeName: (_) => const Page1(), Page2.routeName: (_) => const Page2(), }, ); } } class Page1 extends StatefulWidget { const Page1({Key? key}) : super(key: key); static const String routeName = '/page1'; @override State createState() => _Page1State(); } class _Page1State extends State { bool _checkboxValue = false; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Page 1'), ), body: Column( children: [ TextButton( autofocus: true, // On Safari, this can result in other widgets losing their semantics. onPressed: () => Navigator.pushReplacementNamed(context, Page2.routeName), child: const Text('Page 2 (autofocus)'), ), TextButton( onPressed: () => Navigator.pushReplacementNamed(context, Page2.routeName), child: const Text('Page 2'), ), CheckboxListTile( onChanged: (bool? newValue) => setState(() => _checkboxValue = newValue!), title: const Text('Check me'), value: _checkboxValue, ), ], ), ); } } class Page2 extends StatelessWidget { const Page2({Key? key}) : super(key: key); static const String routeName = '/page2'; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Page 2'), ), body: Column( children: [ TextButton( onPressed: () => Navigator.pushReplacementNamed(context, Page1.routeName), child: const Text('Page 1'), ), ], ), ); } } ```
Logs ``` [✓] Flutter (Channel stable, 3.0.4, on macOS 12.4 21F79 darwin-x64, locale en-US) • Flutter version 3.0.4 at /Users/vsomayaji/Dev/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 85684f9300 (13 days ago), 2022-06-30 13:22:47 -0700 • Engine revision 6ba2af10bb • Dart version 2.17.5 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at /Users/vsomayaji/Library/Android/sdk • Platform android-31, build-tools 30.0.3 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.1) • 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 11.0.11+0-b60-7590822) [✓] IntelliJ IDEA Ultimate Edition (version 2021.1.2) • IntelliJ at /Applications/IntelliJ IDEA.app • 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 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 12.4 21F79 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```

https://user-images.githubusercontent.com/1007109/178851506-8ff2b13d-2675-4708-b58c-4f393d73739f.mov

huycozy commented 2 years ago

Hi @vsomayaji. This issue is reproducible on the stable channel. But it seems to have been fixed on master channel: 3.1.0-0.0.pre.1647. Please watch the recorded video below.

Demo https://user-images.githubusercontent.com/104349824/178936802-7bf3402a-c4e1-4ab3-8695-32b48456a0f2.mov
flutter doctor -v ```bash [✓] Flutter (Channel stable, 3.0.5, on macOS 12.2.1 21D62 darwin-x64, locale en-VN) • Flutter version 3.0.5 at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d570e (9 hours ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • 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 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.69.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0 [✓] Connected device (3 available) • SM T225 (mobile) • R9JT3004VRJ • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ``` ```bash [✓] Flutter (Channel master, 3.1.0-0.0.pre.1647, on macOS 12.2.1 21D62 darwin-x64, locale en-VN) • Flutter version 3.1.0-0.0.pre.1647 on channel master at /Users/huynq/Documents/GitHub/flutter_master • Upstream repository https://github.com/flutter/flutter.git • Framework revision f229b38faf (11 minutes ago), 2022-07-13 23:00:06 -0400 • Engine revision 4f77e8d920 • Dart version 2.18.0 (build 2.18.0-283.0.dev) • DevTools version 2.15.0 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-33, build-tools 31.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 13E113 • CocoaPods version 1.11.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.2) • 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 11.0.12+0-b1504.28-7817840) [✓] IntelliJ IDEA Community Edition (version 2020.3.3) • IntelliJ at /Applications/IntelliJ IDEA CE.app • 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 [✓] IntelliJ IDEA Community Edition (version 2022.1.1) • IntelliJ at /Users/huynq/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/221.5591.52/IntelliJ IDEA CE.app • 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 [✓] VS Code (version 1.69.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.44.0 [✓] Connected device (3 available) • Pixel 3a (mobile) • 964AY0WL20 • android-arm64 • Android 12 (API 32) • macOS (desktop) • macos • darwin-x64 • macOS 12.2.1 21D62 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```

Please try the issue again on the latest master channel and confirm if this issue is fixed.

Note: the screen reader hasn't read autofocus TextButton (Page 2 (autofocus)) as it used to in the stable channel. (1) If you confirm this issue has been fixed and find the same behavior as me at (1), you can update this issue or open new issue for this.

Thanks!

vsomayaji commented 2 years ago

@huycozy thanks for the quick response! I confirmed that I no longer see the lost semantics in the master channel (3.1.0-0.0.pre.1654); however, you're right: in that channel the widget with autofocus: true is not automatically read by the screen reader on load. My guess is that when that regression is fixed, we'll see the lost semantics on Safari again. 😁