Skip to content

Prefer using aria-errormessage above aria-describedby #7425

Open
@fredrikssongustav

Description

@fredrikssongustav

Provide a general summary of the issue here

Looking at https://w3c.github.io/aria/#aria-errormessage it seems this is the preferred way to reference an error. React aria is using aria-describedby instead to reference errors.

🤔 Expected Behavior?

I expect the error reference to use aria-errormessage as it's more accessible.

😯 Current Behavior

Looking at https://react-spectrum.adobe.com/react-aria/TextField.html#html-forms, the dom looks like this:

<div class="react-aria-TextField" data-rac="" data-invalid="true">
   <label class="react-aria-Label"id="react-aria8585958893-:r1m:" for="react-aria8585958893-:r1l:">
   Email
   </label>
   <input type="email" name="email" id="react-aria8585958893-:r1l:" aria-labelledby="react-aria8585958893-:r1m:" class="react-aria-Input" data-rac="" value="asdasd" title="" aria-invalid="true" data-invalid="true" 
      aria-describedby="react-aria8585958893-:r1p:">
   <span class="react-aria-FieldError" slot="errorMessage" data-rac="" id="react-aria8585958893-:r1p:">
   Please include an '@' in the email address. 'asdasd' is missing an '@'.
   </span>
</div>

💁 Possible Solution

Use aria-errormessage. This may be a breaking change.

🔦 Context

This is not playing nicely with Jest selectors: https://github.com/testing-library/jest-dom#toHaveAccessibleErrorMessage, which is probably the most common way to assert your app is accessible.

🖥️ Steps to Reproduce

  1. Go to example https://react-spectrum.adobe.com/react-aria/TextField.html#html-forms
  2. Inspect the DOM

Version

react aria components@latest

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge, Other

If other, please specify.

All likely

What operating system are you using?

MacOS

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    🩺 To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions