Skip to content

[web] when dialog pops up screen reader loses focus instead of focusing on something inside the dialog #138371

@yjbanov

Description

@yjbanov

When dialog pops up screen reader loses focus instead of focusing on something inside the dialog. The Flutter framework expects that the engine will cause the screen reader to focus on something reasonable automatically. In the case of mobile OSes the screen reader implementations do it for you. On the web, screen readers do nothing, and need assistance from the web engine.

The following test reproduces the issue. The dialog contains two buttons, but when it comes up it does not focus on any of them and does not fire a didGainAccessibilityFocus action (see the last expect statement).

  test('focuses on the first unfocused Focusable', () async {
    semantics()
      ..debugOverrideTimestampFunction(() => _testTime)
      ..semanticsEnabled = true;

    final List<CapturedAction> capturedActions = <CapturedAction>[];
    EnginePlatformDispatcher.instance.onSemanticsActionEvent = (ui.SemanticsActionEvent event) {
      capturedActions.add((event.nodeId, event.type, event.arguments));
    };

    final SemanticsTester tester = SemanticsTester(semantics());
    tester.updateNode(
      id: 0,
      scopesRoute: true,
      transform: Matrix4.identity().toFloat64(),
      children: <SemanticsNodeUpdate>[
        tester.updateNode(
          id: 1,
          children: <SemanticsNodeUpdate>[
            tester.updateNode(
              id: 2,
              label: 'Button 1',
              hasTap: true,
              hasEnabledState: true,
              isEnabled: true,
              isButton: true,
              isFocusable: true,
              isFocused: false,
              rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
            ),
            tester.updateNode(
              id: 3,
              label: 'Button 2',
              hasTap: true,
              hasEnabledState: true,
              isEnabled: true,
              isButton: true,
              isFocusable: true,
              isFocused: false,
              rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
            ),
          ],
        ),
      ],
    );
    tester.apply();

    expect(
      capturedActions,
      <CapturedAction>[
        (2, ui.SemanticsAction.didGainAccessibilityFocus, null),
      ],
    );

    semantics().semanticsEnabled = false;
  });

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listengineflutter/engine related. See also e: 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