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

Commit ba94ab7

Browse files
committed
[web] Set the correct href on semantic links
1 parent 6e722ae commit ba94ab7

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ class Link extends PrimaryRoleManager {
1818
@override
1919
DomElement createElement() {
2020
final DomElement element = domDocument.createElement('a');
21-
// TODO(chunhtai): Fill in the real link once the framework sends entire uri.
22-
// https://github.com/flutter/flutter/issues/102535.
23-
element.setAttribute('href', '#');
21+
// TODO: The <a> element has `aria-label={value}`. We should stop that!
22+
element.setAttribute('href', semanticsObject.hasValue ? semanticsObject.value! : '#');
2423
element.style.display = 'block';
2524
return element;
2625
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ abstract class PrimaryRoleManager {
478478
element.style.position = 'absolute';
479479
element.setAttribute('id', 'flt-semantic-node-${semanticsObject.id}');
480480

481+
if (semanticsObject.hasIdentifier) {
482+
element.setAttribute('semantic-identifier', semanticsObject.identifier!);
483+
}
484+
481485
// The root node has some properties that other nodes do not.
482486
if (semanticsObject.id == 0 && !configuration.debugShowSemanticsNodes) {
483487
// Make all semantics transparent. Use `filter` instead of `opacity`
@@ -1085,6 +1089,21 @@ class SemanticsObject {
10851089
_dirtyFields |= _platformViewIdIndex;
10861090
}
10871091

1092+
/// See [ui.SemanticsUpdateBuilder.updateNode].
1093+
String? get identifier => _identifier;
1094+
String? _identifier;
1095+
1096+
bool get hasIdentifier => _identifier != null && _identifier!.isNotEmpty;
1097+
1098+
static const int _identifierIndex = 1 << 24;
1099+
1100+
/// Whether the [identifier] field has been updated but has not been
1101+
/// applied to the DOM yet.
1102+
bool get isIdentifierDirty => _isDirty(_identifierIndex);
1103+
void _markIdentifierDirty() {
1104+
_dirtyFields |= _identifierIndex;
1105+
}
1106+
10881107
/// A unique permanent identifier of the semantics node in the tree.
10891108
final int id;
10901109

@@ -1241,6 +1260,11 @@ class SemanticsObject {
12411260
_markFlagsDirty();
12421261
}
12431262

1263+
if (_identifier != update.identifier) {
1264+
_identifier = update.identifier;
1265+
_markIdentifierDirty();
1266+
}
1267+
12441268
if (_value != update.value) {
12451269
_value = update.value;
12461270
_markValueDirty();

0 commit comments

Comments
 (0)