Skip to content

Omit redundant role="heading" on native heading elements - #2898

Merged
zoontek merged 2 commits into
necolas:masterfrom
bencripps:fix/omit-redundant-heading-role
Oct 21, 2026
Merged

zoontek merged 2 commits into
necolas:masterfrom
bencripps:fix/omit-redundant-heading-role

Conversation

@bencripps

Copy link
Copy Markdown
Contributor

Fixes #2780.

Text with accessibilityRole="header" (or role="heading") already renders an h1–h6. createDOMProps was also setting role="heading" on that element. An explicit heading role overrides the tag's implicit level, so axe no longer counts it as a real heading (h1[role="heading"]).

Native headings now keep their implicit role. A non-heading host, such as a div, still receives role="heading".

Test plan

  • propsToAccessibilityComponent still maps a heading role to h1 / hN
  • createDOMProps('h1' | 'h3', …) does not set role
  • createDOMProps('div', { role: 'heading' }) still sets role="heading"
  • createElement renders <h1> and <h2> with no role attribute
  • jest for createDOMProps and createElement (72 tests)

Made with Cursor

@codesandbox-ci

codesandbox-ci Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit e34775f:

Sandbox Source
react-native-web-examples Configuration

An explicit heading role overrides the implicit level of h1–h6, so axe no longer treats them as real headings.
@zoontek
zoontek force-pushed the fix/omit-redundant-heading-role branch from e34775f to 6ef873c Compare October 21, 2026 15:41
@zoontek

zoontek commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

LGTM, thanks!

@zoontek
zoontek merged commit 48ff8bd into necolas:master Oct 21, 2026
5 checks passed
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.

A11y Text accessible role "heading" render redundant role

2 participants