Skip to content

fix(core/caniuse): add role=img to browser support cells for valid HTML#5176

Merged
marcoscaceres merged 10 commits intomainfrom
fix/caniuse-aria-role
Apr 19, 2026
Merged

fix(core/caniuse): add role=img to browser support cells for valid HTML#5176
marcoscaceres merged 10 commits intomainfrom
fix/caniuse-aria-role

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

The div elements with aria-label lacked a role attribute, violating HTML spec per the Nu validator. Added role=img since the aria-label fully describes the visual content. Set inner img alt to empty to avoid double-announcement.

Closes #5091

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes HTML validity for the “Can I Use” browser support cells by ensuring elements with aria-label have an appropriate ARIA role, aligning generated output with Nu validator requirements (per #5091).

Changes:

  • Add role="img" to caniuse browser support cell containers that use aria-label.
  • Make the nested browser logo <img> decorative by setting alt="" to avoid double announcements.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/caniuse.js
Comment thread src/core/caniuse.js
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot, it's unclear what the right markup is for this from the issue... what does the validator actually say?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

@copilot, it's unclear what the right markup is for this from the issue... what does the validator actually say?

The Nu validator error (from the issue) is:

The "aria-label" attribute must not be specified on any "div" element unless the element has a "role" value other than "caption", "code", "deletion", "emphasis", "generic", "insertion", "paragraph", "presentation", "strong", "subscript", or "superscript".

<div> has an implicit ARIA role of "generic", which is in that prohibited list — so any aria-label on a bare <div> is now an error. The fix is to add an explicit role that is not in the list.

role="img" was chosen because each browser-support cell is a self-contained visual indicator (color-coded cell + browser logo + version number) that is fully described by its aria-label (e.g. "fetch is supported since Chrome version 80 on desktop."). That matches the WAI-ARIA definition of an img landmark — a container whose accessible name completely describes its visual content. With this role, the inner <img> is treated as decorative (alt=""), avoiding double-announcement.

An alternative would be role="figure", which has the same validator-fixing effect but leaves descendants exposed to assistive technology. Since the aria-label already captures all the information visible in the cell, role="img" gives the cleaner AT experience here.

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot, do what you think is best for accessibility here. And also check what's going on with CI... looks like lint issues.

@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot, can you fix the lint issues from CI?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

@copilot, do what you think is best for accessibility here. And also check what's going on with CI... looks like lint issues.

Fixed in 41d74ea. The lint failure was a prettier formatting issue — the ternary for versionSuffix was too long (82 chars) and needed to be broken across lines. The accessibility approach kept as role="img" with aria-label covering all cases including unknown versions ("…since iOS Safari (version unknown) on mobile."), and inner <img alt=""> as decorative.

marcoscaceres and others added 4 commits April 17, 2026 18:58
The div has aria-label with the full description, so children are
presentational. Set inner img alt to empty to avoid double-announcement.
Agent-Logs-Url: https://github.com/speced/respec/sessions/6ae7a1ff-7486-4388-b079-084233604857

Co-authored-by: marcoscaceres <870154+marcoscaceres@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

@copilot, can you fix the lint issues from CI?

Fixed in fb850cf. The prettier lint error was a ternary exceeding the 80-char print width; breaking it across multiple lines resolved it. CI is now passing.

marcoscaceres and others added 3 commits April 18, 2026 02:40
The nullish coalescing operator treats "" as non-nullish, so an
empty-string version would display as blank instead of the em dash
fallback. The ternary correctly maps falsy values (including "")
to the fallback.
marcoscaceres added a commit that referenced this pull request Apr 18, 2026
Avoid injecting a duplicate heading when #bp-summary already has one,
and use prepend() so the generated heading always appears at the top.

Closes #5176
@marcoscaceres marcoscaceres requested a review from Copilot April 18, 2026 12:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes invalid Can I Use markup flagged by the Nu HTML validator by ensuring elements with aria-label have an appropriate ARIA role, while keeping screen reader output clean and consistent with the visible UI.

Changes:

  • Add role="img" to Can I Use browser support cells that use aria-label.
  • Make the inner browser logo image decorative (alt="") to avoid double announcements.
  • Ensure aria-label includes a “(version unknown)” suffix when the displayed version is “—”, and add assertions covering this behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/core/caniuse.js Adds role="img" and updates accessible naming (including unknown-version case) while making the inner logo image decorative.
tests/spec/core/caniuse-spec.js Updates/extends tests to match the new accessibility/validity behavior (alt="", role="img", and unknown-version aria-label).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/caniuse.js
@sidvishnoi sidvishnoi changed the title fix(caniuse): add role=img to browser support cells for valid HTML fix(core/caniuse): add role=img to browser support cells for valid HTML Apr 19, 2026
@marcoscaceres marcoscaceres marked this pull request as draft April 19, 2026 12:44
@marcoscaceres marcoscaceres marked this pull request as ready for review April 19, 2026 19:47
@marcoscaceres marcoscaceres enabled auto-merge (squash) April 19, 2026 19:48
@marcoscaceres marcoscaceres merged commit 509effd into main Apr 19, 2026
9 checks passed
@marcoscaceres marcoscaceres deleted the fix/caniuse-aria-role branch April 19, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

caniuse insert uses invalid markup

4 participants