Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[web] set the "dialog" ARIA role unconditionally #54761

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions lib/web_ui/lib/src/engine/semantics/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class SemanticRoute extends SemanticRole {
// Case 2: nothing requested explicit focus. Focus on the first descendant.
_setDefaultFocus();
});

// Lacking any more specific information, ARIA role "dialog" is the
// closest thing to Flutter's route. This can be revisited if better
// options become available, especially if the framework volunteers more
// specific information about the route. Other attributes in the vicinity
// of routes include: "alertdialog", `aria-modal`, "menu", "tooltip".
setAriaRole('dialog');
}

void _setDefaultFocus() {
Expand Down Expand Up @@ -79,7 +86,6 @@ class SemanticRoute extends SemanticRole {
}());

setAttribute('aria-label', label ?? '');
_assignRole();
}
}

Expand All @@ -91,22 +97,12 @@ class SemanticRoute extends SemanticRole {
return;
}

_assignRole();
setAttribute(
'aria-describedby',
routeName.semanticsObject.element.id,
);
}

void _assignRole() {
// Lacking any more specific information, ARIA role "dialog" is the
// closest thing to Flutter's route. This can be revisited if better
// options become available, especially if the framework volunteers more
// specific information about the route. Other attributes in the vicinity
// of routes include: "alertdialog", `aria-modal`, "menu", "tooltip".
setAriaRole('dialog');
}

@override
bool focusAsRouteDefault() {
// Routes are the ones that look inside themselves to find elements to
Expand Down
7 changes: 2 additions & 5 deletions lib/web_ui/test/engine/semantics/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3110,10 +3110,7 @@ void _testRoute() {
semantics().semanticsEnabled = false;
});

test('scopesRoute alone sets the SemanticRoute role with no label', () {
final List<String> warnings = <String>[];
printWarning = warnings.add;

test('scopesRoute alone sets the SemanticRoute role and "dialog" ARIA role with no label', () {
semantics()
..debugOverrideTimestampFunction(() => _testTime)
..semanticsEnabled = true;
Expand All @@ -3127,7 +3124,7 @@ void _testRoute() {
tester.apply();

expectSemanticsTree(owner(), '''
<sem></sem>
<sem role="dialog"></sem>
''');

expect(
Expand Down