@@ -21,7 +21,6 @@ import '../window.dart';
21
21
import 'accessibility.dart' ;
22
22
import 'checkable.dart' ;
23
23
import 'focusable.dart' ;
24
- import 'header.dart' ;
25
24
import 'heading.dart' ;
26
25
import 'image.dart' ;
27
26
import 'incrementable.dart' ;
@@ -397,17 +396,14 @@ enum SemanticRoleKind {
397
396
/// The node's role is to host a platform view.
398
397
platformView,
399
398
400
- /// Contains a link.
401
- link,
402
-
403
- /// Denotes a header.
404
- header,
405
-
406
399
/// A role used when a more specific role cannot be assigend to
407
400
/// a [SemanticsObject] .
408
401
///
409
402
/// Provides a label or a value.
410
403
generic,
404
+
405
+ /// Contains a link.
406
+ link,
411
407
}
412
408
413
409
/// Responsible for setting the `role` ARIA attribute, for attaching
@@ -692,18 +688,23 @@ final class GenericRole extends SemanticRole {
692
688
return ;
693
689
}
694
690
695
- // Assign one of two roles to the element: group or text.
691
+ // Assign one of three roles to the element: group, heading, text.
696
692
//
697
693
// - "group" is used when the node has children, irrespective of whether the
698
694
// node is marked as a header or not. This is because marking a group
699
695
// as a "heading" will prevent the AT from reaching its children.
696
+ // - "heading" is used when the framework explicitly marks the node as a
697
+ // heading and the node does not have children.
700
698
// - If a node has a label and no children, assume is a paragraph of text.
701
699
// In HTML text has no ARIA role. It's just a DOM node with text inside
702
700
// it. Previously, role="text" was used, but it was only supported by
703
701
// Safari, and it was removed starting Safari 17.
704
702
if (semanticsObject.hasChildren) {
705
703
labelAndValue! .preferredRepresentation = LabelRepresentation .ariaLabel;
706
704
setAriaRole ('group' );
705
+ } else if (semanticsObject.hasFlag (ui.SemanticsFlag .isHeader)) {
706
+ labelAndValue! .preferredRepresentation = LabelRepresentation .domText;
707
+ setAriaRole ('heading' );
707
708
} else {
708
709
labelAndValue! .preferredRepresentation = LabelRepresentation .sizedSpan;
709
710
removeAttribute ('role' );
@@ -1271,24 +1272,11 @@ class SemanticsObject {
1271
1272
bool get isTextField => hasFlag (ui.SemanticsFlag .isTextField);
1272
1273
1273
1274
/// Whether this object represents a heading element.
1274
- ///
1275
- /// Typically, a heading is a prominent piece of text that describes what the
1276
- /// rest of the screen or page is about.
1277
- ///
1278
- /// Not to be confused with [isHeader] .
1279
1275
bool get isHeading => headingLevel != 0 ;
1280
1276
1281
- /// Whether this object represents an interactive link .
1277
+ /// Whether this object represents an editable text field .
1282
1278
bool get isLink => hasFlag (ui.SemanticsFlag .isLink);
1283
1279
1284
- /// Whether this object represents a header.
1285
- ///
1286
- /// A header is a group of widgets that introduce the content of the screen
1287
- /// or a page.
1288
- ///
1289
- /// Not to be confused with [isHeading] .
1290
- bool get isHeader => hasFlag (ui.SemanticsFlag .isHeader);
1291
-
1292
1280
/// Whether this object needs screen readers attention right away.
1293
1281
bool get isLiveRegion =>
1294
1282
hasFlag (ui.SemanticsFlag .isLiveRegion) &&
@@ -1702,8 +1690,6 @@ class SemanticsObject {
1702
1690
return SemanticRoleKind .route;
1703
1691
} else if (isLink) {
1704
1692
return SemanticRoleKind .link;
1705
- } else if (isHeader) {
1706
- return SemanticRoleKind .header;
1707
1693
} else {
1708
1694
return SemanticRoleKind .generic;
1709
1695
}
@@ -1721,7 +1707,6 @@ class SemanticsObject {
1721
1707
SemanticRoleKind .platformView => SemanticPlatformView (this ),
1722
1708
SemanticRoleKind .link => SemanticLink (this ),
1723
1709
SemanticRoleKind .heading => SemanticHeading (this ),
1724
- SemanticRoleKind .header => SemanticHeader (this ),
1725
1710
SemanticRoleKind .generic => GenericRole (this ),
1726
1711
};
1727
1712
}
0 commit comments