Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input aria-invalid attribute is being rendered without a valid ("true") value #3623

Open
soujvnunes opened this issue Jan 25, 2025 · 0 comments

Comments

@soujvnunes
Copy link

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

v2.2.0

What browser are you using?

Chrome Version 131.0.6778.265 (arm64)

Reproduction URL

CodeSandbox

Describe your issue

I'm currently using Storybook to document components and during the customized Headless Input component accessbility testing, a warning about the attribute aria-invalid being empty was triggered:

The empty aria-invalid can also be seen on element inspection in the reproduction URL.

Image

It happens due to how Headless Input currently renders the aria-invalid:

Permalink

// https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/input/input.tsx#L69
'aria-invalid': invalid ? '' : undefined,

I believe that rendering this attribute with a true value ('aria-invalid': invalid ? 'true' : undefined) solves this issue, and this is probably cause by how React misshandles aria-* attributes that require a valid value (in JSX this is considered booleanish, meaning that accepts boolean, 'true' or 'false', but in HTML just ="true" or ="false" is expected)

References:

Note:

Apparently, MDN says that any value different than 'true', 'false', 'spelling' or 'grammar' will be treated like 'true', but as we can read in the references, this attribute must have a valid value (any of the previous ones).

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

No branches or pull requests

1 participant