A2UI icon indicating copy to clipboard operation
A2UI copied to clipboard

Basic Catalog components not rendering accessibility attributes (was: Restaurant Finder example: accessibility of "Book Now")

Open AutoSponge opened this issue 6 months ago • 15 comments

The interface produced violates WCAG 2.4.6 by creating multiple "Book Now" buttons that perform different actions.

What should happen is something like this:

<button style="..."><span style="...">Book<span class="sr-only"> Mott 32 </span>Now</span></button>
<button style="..." aria-label="book mott 32 now"><span style="...">Book Now</span></button>
<button style="..." aria-labelledby="book mott32 now"><span style="..."><span id="book">Book</span>&nbsp;<span id="mott32" style="display:none"> Mott 32 </span><span id="now">Now</span></span></button>

What's responsible for building "invisible" text of the interface? Is it the JSON (maybe the schema is incomplete), the composer, or better inference instructions?

AutoSponge avatar May 12 '26 12:05 AutoSponge

What should happen is something like this [...]

I'm assuming that those 3 are 3 different acceptable options?

ditman avatar May 15 '26 22:05 ditman

@ditman yes. Those should all have similar results in the axTree.

AutoSponge avatar May 16 '26 15:05 AutoSponge

According to the specification, the Button component should contain AccessibilityAttributes to set a "label" and "description".

With that definition, we should be able to produce the second option in your list:

<button style="..." aria-label="book mott 32 now"><span style="...">Book Now</span></button>

(We'd just use the label property as the aria-label of the button component when rendering it.)

I haven't looked at the responses from the restaurant_finder to see if they're passing any accessibility attributes down, but I can't find where the widgets may be rendering their aria-labels (most likely nowhere).

This is a big bug, we need to ensure the accessibility attributes are used in the frontend (and then maybe correct the restaurant_finder sample to ensure they're used there)

ditman avatar May 20 '26 23:05 ditman

A2UI Triage: Classified as a P1 bug. The Lit, Angular, and React renderers need to be updated to support AccessibilityAttributes as defined in the specification to resolve the WCAG 2.4.6 violation.

gspencergoog avatar Jun 29 '26 19:06 gspencergoog

This has been triaged as P1 bug. Removing the needs-triage label.

@gspencergoog Do you know why github-actions added the needs-triage label and then removed it periodically on these triaged issues?

nan-yu avatar Jul 31 '26 17:07 nan-yu

Do you know why github-actions added the needs-triage label and then removed it periodically on these triaged issues?

I don't. Maybe @polina-c does?

gspencergoog avatar Jul 31 '26 17:07 gspencergoog

Oh, actually I do know: it's added in the triage script.

gspencergoog avatar Jul 31 '26 18:07 gspencergoog

I think the rule is that P1 should have an assigned user. A nice improvement to the triage script would be for it to post a message explaining why it added the triage label, during my triage I found myself confused trying to get the script to remove it.

ditman avatar Jul 31 '26 18:07 ditman

This issue was assigned to @josemontespg on June 29th. I think the needs-triage label was added because of this rule d. P1 and stale for more than 30 days, or (https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs#L35C9-L35C50).

nan-yu avatar Jul 31 '26 18:07 nan-yu

I attempted https://github.com/a2ui-project/a2ui/pull/2144 to fix this, but it got pretty large with changes across Angular, React and Lit. I'll address this issue once I complete the work in https://github.com/a2ui-project/a2ui/issues/1270 so that we can fix this consistently across the frameworks.

josemontespg avatar Aug 12 '26 22:08 josemontespg

Some measured specifics from an automated audit of @a2ui/[email protected], in case they are useful for scoping whenever #2144 / #1270 resume. Not a nudge — we are carrying these as documented exclusions on our side.

We render the v0.9 Basic catalog through MessageProcessor + <a2ui-surface> and audit every component with axe-core 4.13 in Chromium at WCAG 2.2 AA. Four things came out, and one of them is a different failure mode from the aria-label/AccessibilityAttributes gap this thread has been discussing.

1. Three components render a visible label that is not associated with its control (axe label, critical):

  • TextField.js — <label> and <input> as siblings, no for, no id, no nesting
  • Slider.js — <label> in a header <div> beside <input type="range">, same shape
  • DateTimeInput.js — <label> beside <input type="date">, same shape

Worth separating from the Button case, because implementing AccessibilityAttributes would not by itself fix these: the author has already supplied a label through the component's own label prop, and it renders — it just computes to no accessible name. Associating the existing label (a for/id pair, or wrapping) fixes them whether or not the schema slot lands.

CheckBox.js and ChoicePicker.js are unaffected — their <label> elements wrap their inputs, so the name computes correctly. That contrast is what makes this look per-component rather than by design.

2. CommonProps.accessibility is declared but unread. The v0.9 schema carries accessibility: { label, description } on every component, but grepping the Lit renderer it appears only in .d.ts declarations — the sole aria- usage anywhere in catalogs/basic/components/ is two attributes in ChoicePicker.js (aria-label="Filter options" and aria-pressed). So an application author cannot currently work around (1) through the schema either.

3. No required state. TextField renders neither required nor aria-required, so a form whose fields are mandatory announces them as optional.

4. Validation errors are unannounced and unassociated. Errors render as <div class="error"> with no aria-live, aria-describedby or aria-invalid, and the invalid state is signalled by border colour alone — silence on a rejected submit for a screen-reader user, and nothing at all for a user who does not perceive the border (WCAG 1.4.1, 3.3.1).

Separately, one contrast finding that is unrelated to naming: the primary Button variant paints #ffffff on #1177ee, which measures 4.28:1 against WCAG 1.4.3's 4.5:1 for body text at the default 13.3px. Correcting my own closing sentence, which said a slightly darker blue clears it — it does not. The borderless variant uses that same token as its text colour, so a blue dark enough to fix the filled variant fails as text on a dark host: #0b63cc measures 5.72:1 as a fill under white, but 3.12:1 as text on #0f172a. The token has to invert per scheme rather than darken — #ffffff on #0b63cc in light, #0f172a on #60a5fa in dark, measured 5.72:1 and 7.02:1. The per-scheme mechanics are in the color-scheme coupling report later in this thread (https://github.com/a2ui-project/a2ui/issues/1410#issuecomment-5648260302).

Happy to share the fixture page (one v0.9 surface per Basic component) or the raw axe output if either would help. On our side these are enumerated per rule and per component with a test that fails when any of them starts passing, so a release that fixes them forces our exclusions out rather than leaving them behind.

clicks-steve avatar Sep 09 '26 16:09 clicks-steve

One more from the same audit, found after the comment above once we drove a real checks failure through TextField: the message it renders in .error is coloured by --a2ui-textfield-color-error, whose default is red. #ff0000 on #ffffff measures 3.99:1 at the 11px it renders at (WCAG 1.4.3 asks 4.5:1), and on a dark host (#16181d in our fixture) it is 4.44:1 — under the line either way, because TextField paints no background of its own, so the pair is always red on whatever the host provides. A slightly darker default, or exposing the token so the host can set it, clears 4.5:1 on both.

Same posture as the four above: carried as a documented exclusion on our side, with a test that fails when it starts passing, so a release that changes the default removes our exclusion rather than leaving it behind.

Correction: the "slightly darker default … clears 4.5:1 on both" sentence above is wrong. Against white the text needs relative luminance ≤ 0.183; against a dark host like #16181d it needs ≥ 0.216 — the two constraints are disjoint, so darkening red fixes the light case while worsening the dark one. What clears both is a scheme-aware colour whose switch is the same one the background follows — and that qualifier is the whole of it, as the color-scheme coupling report later in this thread shows (https://github.com/a2ui-project/a2ui/issues/1410#issuecomment-5648260302). A bare light-dark() pair is not sufficient: it resolves from the color-scheme property while a host's background typically follows a prefers-color-scheme media query, and when a page pins color-scheme the two pick opposite arms. That lands ACE's own error pair at #b91c1c on #0f172a (2.76:1) or #fca5a5 on #ffffff (1.90:1) — both worse than the defect being fixed. So: a light-dark() pair plus color-scheme: light dark declared on the element that carries it, or a prefers-color-scheme rule on both halves, or the component painting its own background so the pair is under its control. Exposing the token still helps, but the host would need to set it per scheme.

KevinRay avatar Sep 09 '26 21:09 KevinRay

To change the default error color, the host application just needs to define the --a2ui-textfield-color-error CSS variable on a parent element, as CSS custom properties naturally inherit down the DOM tree (and even pierce through Shadow DOM boundaries).

For example

/* In the component stylesheet where the A2UI surface is hosted */
.my-a2ui-surface-container {
  --a2ui-textfield-color-error: #ff5722;
}
<!-- In the template -->
<div class="my-a2ui-surface-container">
  <!-- A2UI components rendered inside here will inherit the custom color -->
</div>

Note: You could also set --a2ui-color-error instead if you wanted to change the error color for all A2UI components globally, not just TextFields.

josemontespg avatar Sep 09 '26 21:09 josemontespg

A third finding from the same audit, and a different class from the two above: those are default colour values, this is the switching mechanism. Reported against @a2ui/[email protected] and @a2ui/[email protected].

The mechanism. injectBasicCatalogStyles (web_core), called from BasicCatalogA2uiLitElement.connectedCallback (lit), injects the default theme into document.adoptedStyleSheets. Most of its colours switch on the color-scheme property: of the 17 --a2ui-color-* tokens, 9 are literal light-dark() pairs and 4 more inherit the switch through them (--a2ui-color-primary-hover and --a2ui-color-secondary-hover are light-dark() of other tokens; --a2ui-color-secondary-light and -dark are color-mix()es of a pair) — 13 scheme-dependent in all. The exceptions are the primary family: the flat --a2ui-color-primary: #17e and --a2ui-color-on-primary: #fff, plus --a2ui-color-primary-light and -dark, which are color-mix()es of that flat hex and so do not vary either. The same sheet sets color-scheme: light dark at :where(:root). The zero specificity is deliberate and the source comment says so ("allowing page styles to override these defaults as needed without having to deal with specificity"), which is a good property. The consequence is the part worth documenting: because the switch is color-scheme, an ordinary host rule like :root { color-scheme: light } silently takes it over.

A host that themes components with a prefers-color-scheme media query — the usual way to honour a visitor's preference — is then on a different switch from the theme it is overriding. The host's surfaces follow the visitor; upstream's foregrounds follow whatever the page pinned. They can resolve to opposite schemes, and the result is not a subtle shift but an invisible label.

Measured in Chromium, on our own widget, with the host's palette applied and only the color-scheme declaration absent:

host page visitor prefers pair (--a2ui-color-on-secondary over the host surface) ratio
:root { color-scheme: light } dark #333333 on #1e293b 1.16:1
:root { color-scheme: dark } light #eeeeee on #ffffff 1.16:1

Both are ordinary host configurations, and both fail silently — the Button's default-variant label simply disappears.

The workaround we shipped, offered for other hosts rather than as the resolution: declare color-scheme: light dark on the element that carries the theme overrides (for us, the host element the surface is mounted into). The value is the load-bearing part, not the property: light dark re-opts that subtree into both schemes so light-dark() resolves from the visitor's preference — the same signal the media query reads — and the two agree again. A single-value light or dark fixes one scheme and pins the other; inherit takes the page's pinned value and so reproduces the defect; normal opts out of both and forces the light arm. It is one line, and it is correct regardless of what you decide here — we are not asking for it back.

Two fixes you could make, so this is actionable rather than a complaint:

  1. Document it. State that the default theme is color-scheme-driven, and that a host mixing it with prefers-color-scheme must declare color-scheme: light dark on its overriding element — naming the value, since light, dark, inherit and normal each fail differently. This is a docs change and would have saved us the audit. You already ship a2ui-light / a2ui-dark classes that set color-scheme, and the JSDoc on DEFAULT_CSS explains the intent — so the coupling is already the design. It is just not stated anywhere a host integrator meets it: neither package's README mentions color-scheme, light-dark or those class names.
  2. Drive the default theme from prefers-color-scheme too, so a host's media queries agree with it by construction. That is a behaviour change and would want its own discussion — a host that deliberately pins color-scheme would lose the ability to pin the theme with it.

We have no preference between them; (1) alone would have been enough for us.

KevinRay avatar Sep 12 '26 19:09 KevinRay

This is still being worked on! As part of migrating the basic catalog to universal web component API, we should also ensure all a11y attributes are set correctly.

yjbanov avatar Oct 29 '26 20:10 yjbanov