Skip to content

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

@vsomayaji

Description

@vsomayaji

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
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<Page1> createState() => _Page1State();
}

class _Page1State extends State<Page1> {
  bool _checkboxValue = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Page 1'),
      ),
      body: Column(
        children: <Widget>[
          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: <Widget>[
          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!
SafariLosesSemantics.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)browser: safari-macosonly manifests in Safari on macOScustomer: troyf: focusFocus traversal, gaining or losing focusframeworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specificallyteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions