-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
- Check if updating to the latest Preact version resolves the issue
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 a role="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:
- Using
null
: It keeps therole
attribute in the element. - Using an empty string: It keeps the
role
attribute in the element. - Using false: It sets
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 using null
. 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 the div
containing the <pre>
element changes.
React behavior
Using this CodeSandbox, toggle between the different options to see how the role
attribute of the div
containing the <pre>
element changes.
Expected behavior
It should be possible to remove the role
attribute as it happens in React.