Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[web] Set the correct href on semantic links
  • Loading branch information
mdebbar committed May 31, 2024
commit ee6a908e43fc9e06fbb669fea166ded9ec450557
5 changes: 2 additions & 3 deletions lib/web_ui/lib/src/engine/semantics/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class Link extends PrimaryRoleManager {
@override
DomElement createElement() {
final DomElement element = domDocument.createElement('a');
// TODO(chunhtai): Fill in the real link once the framework sends entire uri.
// https://github.com/flutter/flutter/issues/102535.
element.setAttribute('href', '#');
// TODO: The <a> element has `aria-label={value}`. We should stop that!
element.setAttribute('href', semanticsObject.hasValue ? semanticsObject.value! : '#');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is going to use value as href, then this role manager should not use the withBasics super constructor, because that one adds the LabelAndValue role which includes value in the label. Alternatively, we can make LabelAndValue configurable so it does not include value in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it by introducing an allowlist labelSources (also used it for incrementable, which was hardcoded as a one-off case).

element.style.display = 'block';
return element;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/web_ui/lib/src/engine/semantics/semantics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ abstract class PrimaryRoleManager {
..overflow = 'visible';
element.setAttribute('id', 'flt-semantic-node-${semanticsObject.id}');

if (semanticsObject.hasIdentifier) {
element.setAttribute('semantic-identifier', semanticsObject.identifier!);
}

// The root node has some properties that other nodes do not.
if (semanticsObject.id == 0 && !configuration.debugShowSemanticsNodes) {
// Make all semantics transparent. Use `filter` instead of `opacity`
Expand Down Expand Up @@ -1097,6 +1101,21 @@ class SemanticsObject {
_dirtyFields |= _platformViewIdIndex;
}

/// See [ui.SemanticsUpdateBuilder.updateNode].
String? get identifier => _identifier;
String? _identifier;

bool get hasIdentifier => _identifier != null && _identifier!.isNotEmpty;

static const int _identifierIndex = 1 << 24;

/// Whether the [identifier] field has been updated but has not been
/// applied to the DOM yet.
bool get isIdentifierDirty => _isDirty(_identifierIndex);
void _markIdentifierDirty() {
_dirtyFields |= _identifierIndex;
}

/// A unique permanent identifier of the semantics node in the tree.
final int id;

Expand Down Expand Up @@ -1253,6 +1272,11 @@ class SemanticsObject {
_markFlagsDirty();
}

if (_identifier != update.identifier) {
_identifier = update.identifier;
_markIdentifierDirty();
}

if (_value != update.value) {
_value = update.value;
_markValueDirty();
Expand Down