Skip to content

Fix role computation of elements based on names#2145

Open
Jym77 wants to merge 8 commits into
mainfrom
named-by-author-exceptions
Open

Fix role computation of elements based on names#2145
Jym77 wants to merge 8 commits into
mainfrom
named-by-author-exceptions

Conversation

@Jym77

@Jym77 Jym77 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Resolves #298
Resolves #1757

  • <aside> and <section> without a name are correctly getting the generic role as default.
  • <img alt="" /> with a name are correctly getting the image role as default.

Browsers do currently differ on the corner cases (empty or whitespace aria-label or title, aria-labelledby referring to invalid or empty elements). We mostly follow what Chrome does as it is the most frequently used browser. Hopefully these behaviours will be clarified in the specifications or the WPT and browsers will align; at which point we should follow suite.

<form> without a name are special. They still need to be treated as forms by Assistive Technologies (for interaction purpose, …) but are not treated as landmarks. The old hasIncorrectRoleWithoutName predicate has been renamed isNotLandmarkWithoutName and only handles the <form> case now.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bbf8039

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 76 packages
Name Type
@siteimprove/alfa-aria Minor
@siteimprove/alfa-rules Minor
@siteimprove/alfa-act Minor
@siteimprove/alfa-affine Minor
@siteimprove/alfa-applicative Minor
@siteimprove/alfa-array Minor
@siteimprove/alfa-bits Minor
@siteimprove/alfa-branched Minor
@siteimprove/alfa-cache Minor
@siteimprove/alfa-callback Minor
@siteimprove/alfa-cascade Minor
@siteimprove/alfa-clone Minor
@siteimprove/alfa-collection Minor
@siteimprove/alfa-comparable Minor
@siteimprove/alfa-continuation Minor
@siteimprove/alfa-css-feature Minor
@siteimprove/alfa-css Minor
@siteimprove/alfa-device Minor
@siteimprove/alfa-dom Minor
@siteimprove/alfa-eaa Minor
@siteimprove/alfa-earl Minor
@siteimprove/alfa-either Minor
@siteimprove/alfa-emitter Minor
@siteimprove/alfa-encoding Minor
@siteimprove/alfa-equatable Minor
@siteimprove/alfa-flags Minor
@siteimprove/alfa-fnv Minor
@siteimprove/alfa-foldable Minor
@siteimprove/alfa-functor Minor
@siteimprove/alfa-generator Minor
@siteimprove/alfa-graph Minor
@siteimprove/alfa-hash Minor
@siteimprove/alfa-http Minor
@siteimprove/alfa-iana Minor
@siteimprove/alfa-iterable Minor
@siteimprove/alfa-json-ld Minor
@siteimprove/alfa-json Minor
@siteimprove/alfa-lazy Minor
@siteimprove/alfa-list Minor
@siteimprove/alfa-map Minor
@siteimprove/alfa-mapper Minor
@siteimprove/alfa-math Minor
@siteimprove/alfa-monad Minor
@siteimprove/alfa-network Minor
@siteimprove/alfa-option Minor
@siteimprove/alfa-painting-order Minor
@siteimprove/alfa-parser Minor
@siteimprove/alfa-performance Minor
@siteimprove/alfa-predicate Minor
@siteimprove/alfa-record Minor
@siteimprove/alfa-rectangle Minor
@siteimprove/alfa-reducer Minor
@siteimprove/alfa-refinement Minor
@siteimprove/alfa-result Minor
@siteimprove/alfa-rng Minor
@siteimprove/alfa-sarif Minor
@siteimprove/alfa-selective Minor
@siteimprove/alfa-selector Minor
@siteimprove/alfa-sequence Minor
@siteimprove/alfa-set Minor
@siteimprove/alfa-slice Minor
@siteimprove/alfa-string Minor
@siteimprove/alfa-style Minor
@siteimprove/alfa-table Minor
@siteimprove/alfa-test Minor
@siteimprove/alfa-thunk Minor
@siteimprove/alfa-time Minor
@siteimprove/alfa-toolchain Minor
@siteimprove/alfa-trampoline Minor
@siteimprove/alfa-tree Minor
@siteimprove/alfa-trilean Minor
@siteimprove/alfa-tuple Minor
@siteimprove/alfa-url Minor
@siteimprove/alfa-wcag Minor
@siteimprove/alfa-web Minor
@siteimprove/alfa-xpath Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Jym77 Jym77 self-assigned this Jul 16, 2026
@Jym77 Jym77 added the major Backwards-incompatible change that touches public API label Jul 16, 2026
@github-project-automation github-project-automation Bot moved this to 🧑‍💻 Doing in ⚙️ Alfa Development Jul 16, 2026
@Jym77

Jym77 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

!pr extract

@Jym77
Jym77 marked this pull request as ready for review July 16, 2026 12:29
@Jym77
Jym77 requested a review from a team as a code owner July 16, 2026 12:29
@pooya-si
pooya-si requested a review from Copilot July 17, 2026 12:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Alfa’s implicit role computation for elements whose role depends on author-provided naming mechanisms (notably <section>, <aside> in sectioning scope, and <img alt="">), and simplifies affected rules by removing the previous workaround predicate in favor of a narrower <form>-specific landmark exclusion.

Changes:

  • Adjust implicit role mapping in @siteimprove/alfa-aria so <section>/<aside> without an author-provided name resolve to generic, and <img alt=""> with an author-provided name resolve to img (otherwise remain presentational/omitted).
  • Replace the broad DOM.hasIncorrectRoleWithoutName workaround with DOM.isNotLandmarkWithoutName to handle the special <form> landmark behavior.
  • Add/adjust tests and changesets to cover the updated role/landmark behaviors.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/alfa-rules/test/sia-r2/rule.spec.tsx Adds rule coverage for <img alt=""> name edge cases impacting pass/fail outcomes.
packages/alfa-rules/src/sia-r57/rule.ts Switches landmark filtering workaround to isNotLandmarkWithoutName (form-only).
packages/alfa-rules/src/sia-r56/rule.ts Updates landmark grouping applicability to exclude unnamed <form> landmarks via new predicate.
packages/alfa-rules/src/sia-r55/rule.ts Same as R56: filters out unnamed <form> landmarks using new predicate.
packages/alfa-rules/src/sia-r40/rule.ts Removes the workaround reject, relying on corrected role computation for region.
packages/alfa-aria/test/tsconfig.json Swaps removed predicate test for the new predicate test file.
packages/alfa-aria/test/role.spec.tsx Adds role computation tests for named/unnamed <section>, scoped/unscoped <aside>, and alt-less named images.
packages/alfa-aria/test/dom/predicate/is-not-landmark-without-name.spec.tsx Introduces tests for the new <form> landmark-exclusion predicate.
packages/alfa-aria/test/dom/predicate/has-incorrect-role-without-name.spec.tsx Removes tests for the deprecated predicate.
packages/alfa-aria/src/tsconfig.json Removes old predicate source file and adds the new predicate source file.
packages/alfa-aria/src/index.ts Exposes DOM.isNotLandmarkWithoutName instead of DOM.hasIncorrectRoleWithoutName.
packages/alfa-aria/src/feature.ts Implements name-dependent implicit role logic for <aside>, <section>, and <img alt="">.
packages/alfa-aria/src/dom/predicate/is-not-landmark-without-name.ts Adds new predicate capturing “unnamed <form> is not a landmark” logic.
packages/alfa-aria/src/dom/predicate/has-incorrect-role-without-name.ts Removes the broad workaround predicate implementation.
packages/alfa-aria/src/dom/dom.ts Updates DOM predicate exports to match the new predicate set.
docs/review/api/alfa-aria.api.md Updates API review surface to reflect predicate rename/removal.
.changeset/wacky-cats-stand.md Declares the breaking predicate replacement in @siteimprove/alfa-aria.
.changeset/old-pillows-wash.md Notes the fix for alt-less but named images being exposed as img.
.changeset/chubby-dolls-type.md Notes the fix for <aside>/<section> name-dependent role computation.

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

Comment thread packages/alfa-aria/test/dom/predicate/is-not-landmark-without-name.spec.tsx Outdated
Comment thread packages/alfa-aria/src/feature.ts Outdated
Comment thread .changeset/chubby-dolls-type.md Outdated
Comment thread .changeset/wacky-cats-stand.md Outdated
Jym77 and others added 4 commits July 17, 2026 14:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

major Backwards-incompatible change that touches public API

Projects

Status: 🧑‍💻 Doing

2 participants