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

Commit e6272f2

Browse files
committed
add test; clean-up
1 parent 9ff0d64 commit e6272f2

File tree

4 files changed

+273
-23
lines changed

4 files changed

+273
-23
lines changed

lib/web_ui/lib/src/engine/semantics/dialog.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Dialog extends PrimaryRoleManager {
2121
// focus on something inside it. There could be two possibilities:
2222
//
2323
// 1. The framework explicitly marked a node inside the dialog as focused
24-
// via the `isFocusabe` and `isFocused` flags. In this case, the node
24+
// via the `isFocusable` and `isFocused` flags. In this case, the node
2525
// will request focus directly and there's nothing to do on top of that.
2626
// 2. No node inside the route takes focus explicitly. In this case, the
2727
// expectation is to look through all nodes in traversal order and focus
@@ -45,7 +45,7 @@ class Dialog extends PrimaryRoleManager {
4545
}
4646

4747
// If the node does not take focus (e.g. focusing on it does not make
48-
// sense at all), depair not. Keep looking.
48+
// sense at all). Despair not. Keep looking.
4949
final bool didTakeFocus = roleManager.focusAsRouteDefault();
5050
return !didTakeFocus;
5151
});
@@ -94,7 +94,7 @@ class Dialog extends PrimaryRoleManager {
9494
@override
9595
bool focusAsRouteDefault() {
9696
// Dialogs are the ones that look inside themselves to find elements to
97-
// focus one. It doesn't make sense to focus on the dialog itself.
97+
// focus on. It doesn't make sense to focus on the dialog itself.
9898
return false;
9999
}
100100
}

lib/web_ui/lib/src/engine/semantics/focusable.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,16 @@ class Focusable extends RoleManager {
3434

3535
final AccessibilityFocusManager _focusManager;
3636

37+
/// Requests focus as a result of a route (e.g. dialog) deciding that the node
38+
/// managed by this class should be focused by default when nothing requests
39+
/// focus explicitly.
40+
///
41+
/// This method of taking focus is different from the regular method of using
42+
/// the [SemanticsObject.hasFocus] flag, as in this case the framework is not
43+
/// explicitly request focus. Instead, the DOM element is being focus directly
44+
/// programmatically, simulating the screen reader choosing a default element
45+
/// to focus on.
3746
bool focusAsRouteDefault() {
38-
print('>>> ${semanticsObject.id} is taking default route focus (label: ${semanticsObject.label})');
3947
owner.element.focus();
4048
return true;
4149
}
@@ -237,7 +245,6 @@ class AccessibilityFocusManager {
237245
return;
238246
}
239247

240-
print('>>> calling focus on ${target.element} id="${target.element.id}"');
241248
target.element.focus();
242249
});
243250
}

lib/web_ui/lib/src/engine/semantics/semantics.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,22 +643,27 @@ final class GenericRole extends PrimaryRoleManager {
643643

644644
@override
645645
bool focusAsRouteDefault() {
646-
final Focusable? focusable = this.focusable;
647-
648-
if (focusable != null) {
649-
return focusable.focusAsRouteDefault();
646+
// Case 1: current node has input focus. Let the input focus system decide
647+
// default focusability.
648+
if (semanticsObject.isFocusable) {
649+
final Focusable? focusable = this.focusable;
650+
if (focusable != null) {
651+
return focusable.focusAsRouteDefault();
652+
}
650653
}
651654

655+
// Case 2: current node is not focusable, but just a container of other
656+
// nodes or lacks a label. Do not focus on it and let the search continue.
652657
if (semanticsObject.hasChildren || !semanticsObject.hasLabel) {
653-
// Unless the container is explicitly focusable (handled above), do not
654-
// autofocus on the container itself. Instead, look for a child to focus
655-
// on.
656658
return false;
657659
}
658660

661+
// Case 3: current node is visual/informational. Move just the
662+
// accessibility focus.
663+
659664
// Plain text nodes should not be focusable via keyboard or mouse. They are
660665
// only focusable for the purposes of focusing the screen reader. To achieve
661-
// that -1 is used.
666+
// this the -1 value is used.
662667
//
663668
// See also:
664669
//
@@ -1773,7 +1778,6 @@ class SemanticsObject {
17731778
final bool shouldContinueVisiting = callback(this);
17741779

17751780
if (!shouldContinueVisiting) {
1776-
print('>>> ${primaryRole?.runtimeType} stopped visitDepthFirstInTraversalOrder');
17771781
return false;
17781782
}
17791783

0 commit comments

Comments
 (0)