-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
It is not possible to remove the role
attribute which results in invalid HTML
#4136
Comments
Interestingly, your Preact sandbox seems to work as you'd expect in FireFox ( Edit: Ah, FF doesn't add it ( |
Exactly; most browsers seem to have implemented the properties defined in the Examples:
|
In the browsers where Line 126 in 7dc66bc
That makes Preact assign an empty string to Line 129 in 7dc66bc
However, the value assigned in this case should be Maybe the fix is just a matter of adding another check above? Like those for |
@DAreRodz That analysis is spot on. Feel free to make a PR that adds it to the list (+ a test) 👍 |
Thanks @marvinhagemeister! I've created this PR, ready for review. 😄 |
Describe the bug
It seems impossible to toggle between having a role attribute (
dialog
for example) and removing the attribute. For example, I want to have arole="dialog"
when a menu is open, but remove the role attribute when it is closed. It currently returns an empty value. This affects accessibility because having an empty role is not valid HTML. You can check that using an HTML validator:This seems to be the behavior in Preact with the following options:
null
: It keeps therole
attribute in the element.role
attribute in the element.role="false"
.I also tried using another role value as
none
, but it changes the accessibility tree.I made a quick video using this CodeSandbox explaining that better:
Sandbox.-.CodeSandbox.-.19.September.2023.mp4
I've tested it in React, and it seems possible to remove the
role
attribute by usingnull
. I used this other CodeSandbox as shown in this other video:React.App.-.19.September.2023.mp4
To Reproduce
Preact behavior
Using this CodeSandbox, toggle between the different options to see how the
role
attribute of thediv
containing the<pre>
element changes.React behavior
Using this CodeSandbox, toggle between the different options to see how the
role
attribute of thediv
containing the<pre>
element changes.Expected behavior
It should be possible to remove the
role
attribute as it happens in React.The text was updated successfully, but these errors were encountered: