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

Commit 9ff0d64

Browse files
committed
handle case when container is focusable
1 parent 22c69c4 commit 9ff0d64

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,10 +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();
650+
}
651+
646652
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.
647656
return false;
648657
}
649-
element.tabIndex = 0;
658+
659+
// Plain text nodes should not be focusable via keyboard or mouse. They are
660+
// only focusable for the purposes of focusing the screen reader. To achieve
661+
// that -1 is used.
662+
//
663+
// See also:
664+
//
665+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
666+
element.tabIndex = -1;
650667
element.focus();
651668
return true;
652669
}

0 commit comments

Comments
 (0)