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

Commit ee6a908

Browse files
committed
[web] Set the correct href on semantic links
1 parent 02f4e59 commit ee6a908

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
@@ -480,6 +480,10 @@ abstract class PrimaryRoleManager {
480480
..overflow = 'visible';
481481
element.setAttribute('id', 'flt-semantic-node-${semanticsObject.id}');
482482

483+
if (semanticsObject.hasIdentifier) {
484+
element.setAttribute('semantic-identifier', semanticsObject.identifier!);
485+
}
486+
483487
// The root node has some properties that other nodes do not.
484488
if (semanticsObject.id == 0 && !configuration.debugShowSemanticsNodes) {
485489
// Make all semantics transparent. Use `filter` instead of `opacity`
@@ -1097,6 +1101,21 @@ class SemanticsObject {
10971101
_dirtyFields |= _platformViewIdIndex;
10981102
}
10991103

1104+
/// See [ui.SemanticsUpdateBuilder.updateNode].
1105+
String? get identifier => _identifier;
1106+
String? _identifier;
1107+
1108+
bool get hasIdentifier => _identifier != null && _identifier!.isNotEmpty;
1109+
1110+
static const int _identifierIndex = 1 << 24;
1111+
1112+
/// Whether the [identifier] field has been updated but has not been
1113+
/// applied to the DOM yet.
1114+
bool get isIdentifierDirty => _isDirty(_identifierIndex);
1115+
void _markIdentifierDirty() {
1116+
_dirtyFields |= _identifierIndex;
1117+
}
1118+
11001119
/// A unique permanent identifier of the semantics node in the tree.
11011120
final int id;
11021121

@@ -1253,6 +1272,11 @@ class SemanticsObject {
12531272
_markFlagsDirty();
12541273
}
12551274

1275+
if (_identifier != update.identifier) {
1276+
_identifier = update.identifier;
1277+
_markIdentifierDirty();
1278+
}
1279+
12561280
if (_value != update.value) {
12571281
_value = update.value;
12581282
_markValueDirty();

0 commit comments

Comments
 (0)