Repository navigation
[#25] Added 'hiddenTextSelector' and 'labelFilter' to clean visually hidden text out of labels. - #28
Merged
Merged
Conversation
|
Warning Review limit reached
This review includes 14 billable files and costs up to $3.50.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 36 minutes for your next included review. View limit details
|
… text out of labels.
… rewrite labels before they are sent.
AlexSkrypnyk
force-pushed
the
feature/25-hidden-text
branch
from
November 16, 2026 09:39
50b54b0 to
efd93da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #25
Summary
Sites get 2 ways to clean the labels in
link_text,group_title,subgroup_titleandfield_label. ThehiddenTextSelectorsetting drops whole elements, such as CivicTheme's.ct-visually-hiddensuffix, and it works fromdrupalSettings.axel. ThelabelFilter(label, element)setting rewrites each label's text. BecausedrupalSettingscan't hold a function, both integrations also read it fromwindow.axelLabelFilter.Screen-reader-only text was always part of the label. On a CivicTheme site, every external link sent
link_text: Docs(Opens in a new tab/window), so the same CTA split into 2 report rows depending on its target. 3 icon-only social links all sent(Opens in a new tab/window)and collapsed into 1 row, even though each had atitle.Both settings are off by default, so nothing changes until a site sets one. When the selector or the filter leaves a label empty, it falls back to
aria-label, thentitle(fields stop ataria-label), then the full text with the hidden elements kept. An icon button named only by a visually hiddenClose, a visually hidden<label>or Drupal's visually hidden menu<h2>keeps the label it sends today. A filter that throws, throws a non-Erroror returns a non-string logs to the console and leaves the label unchanged, so the event still goes out. Form controls stay out of every label on every pass, so the privacy guarantees are unchanged.Before / After
Changes
Label building (
src/core/dom.js)getText(node, hiddenSelector)returns''for an element matching the selector.getTextLabel(node, element, fallback, { hiddenSelector, filter })holds the fallback order once: filtered text without hidden elements, thenfallback, then the filtered full text when a selector is set.getLabel(element, options)uses it witharia-label || titleas the fallback. An input button'svaluegoes through the filter too.collapseWhitespace()replaces the 2 inline copies of the whitespace regex.Core (
src/core/core.js)DEFAULT_SETTINGSaddshiddenTextSelector: ''andlabelFilter: null.labelFilterisn't a function, like it does for collectors, and buildslabelOptionsonce for every label helper.filterLabel(label, element)runs the filter and keeps the label when it throws or returns a non-string. It logserror?.message ?? error, so a thrownnullcan't break the event.Event types
click.jspassesaxel.labelOptionstogetLabel()forlink_textand throughgetGroupTitle()for both titles.field-complete.js:getFieldLabel()usesgetTextLabel()with the field'saria-labelas the fallback, and passes the field to the filter.Integrations
drupal.jssetslabelFilterfromwindow.axelLabelFilter.standalone.jspreferswindow.axelSettings.labelFilter, thenwindow.axelLabelFilter.Tests
tests/fixtures/cases.htmladdscase-click-hidden-textandcase-field-hidden-text. They show that hidden text stays in the label by default, across link suffixes, icon links withtitleoraria-label, an icon button, group and subgroup titles and field labels.click.test.jsandfield-complete.test.jscover:hiddenTextSelector.labelFilter, where icon links fall back to theirtitle.core.test.jscovers the filter arguments, a non-function filter at construction, and a filter that throws, throwsnull, returns a number or returns nothing.drupal.test.jsandstandalone.test.jscoverwindow.axelLabelFilter, and the settings filter winning on a plain page.Docs
README.mdadds a "Label filter" section with the CivicTheme regex example. It also adds both settings to the Settings table, updates thelink_text,field_labeland group title rules, and listswindow.axelLabelFilterunder Security.link_textis no longer described as "visible" text, since visually hidden text is part of it by default.docs/architecture/README.mdcoversgetTextLabel(),filterLabel(),labelOptionsand the integrations readingwindow.axelLabelFilter.Decisions
drupalSettings. The filter covers text a selector can't reach, such as a suffix inside the same text node.case-click-nestedalready reportsRead more: Spring salefrom a.visually-hiddenspan, so some sites rely on hidden context text. Defaulting to.visually-hidden, .sr-onlywould change their reports..ct-visually-hiddenor a filter itself.aria-label, thentitle. The extra last step means the selector never empties a label that has text today.aria-labelandtitle. The page author wrote those as names, so they go out as they are.