resolveClickName function

ClickName resolveClickName(
  1. ClickTarget target
)

The name a tap is reported under, first match wins:

  1. the host's ClickTarget.identifier, verbatim — so an existing <id>_pressed never changes;
  2. the label, slugged;
  3. the visible text, slugged;
  4. (RN and Flutter) the icon / image / SVG name, ClickTarget.visual;
  5. the role, else the component, lowercased.

Steps 2 to 4 are skipped for a ClickTarget.redacted control. An identifier that identifiesSomeone is skipped too.

Implementation

ClickName resolveClickName(ClickTarget target) {
  final identifier = target.identifier?.trim();
  if (identifier != null &&
      identifier.isNotEmpty &&
      !identifiesSomeone(identifier)) {
    return ClickName(identifier, isFallback: false);
  }
  if (!target.redacted) {
    for (final source in [target.label, target.text]) {
      final stem = slugClickName(source);
      if (stem.isNotEmpty) return ClickName(stem, isFallback: false);
    }
    final visual = target.visual?.trim();
    if (visual != null && visual.isNotEmpty) {
      return ClickName(visual, isFallback: false);
    }
  }
  final component = target.component.toLowerCase();
  return ClickName(
    target.role ?? (component.isEmpty ? 'view' : component),
    isFallback: true,
  );
}