False value cause aria boolean attributes to be removed from the DOM
See original GitHub issueVersion
2.6.11
Reproduction link
https://www.dropbox.com/s/3ltqeent65djedw/problematic-false-aria-values.zip?dl=0
Steps to reproduce
- Extract the provided zip archive and enter the produced “problematic-false-aria-values” directory.
- Install dependencies (i.e.
yarn install
). - Run the development server (i.e.
yarn serve
) and head to its url with your favorite browser. - Inspect the DOM of the page: the
aria-checked
andaria-expanded
attributes won’t be there. - Enable the checkbox and/or expand the toggle.
- Inspect the DOM of the page: this time both
aria-checked
andaria-expanded
will be there as expected. - Disable the checkbox and collapse the toggle.
- Inspect the DOM of the page: the
aria-checked
andaria-expanded
attributes won’t be there, again.
What is expected?
Aria attributes should be present in the DOM even if their value is false.
What is actually happening?
Aria attributes are not present in the DOM when their value is false.
Unlike for html 5 boolean values, removing aria attributes from the DOM when their value is false changes the page semantics and degrades its accessibility, causing markup validation issues as well.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
aria-invalid - Accessibility - MDN Web Docs
The aria-invalid attribute is used to indicate that the value entered into an input field is not in a format or a value...
Read more >Boolean attributes in HTML and ARIA: what's the difference?
The values “true” and “false” are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether....
Read more >ByRole | Testing Library
Note that no aria-current attribute will match current: false since false is the default value for aria-current .
Read more >Expressions - Lit.dev
Boolean attributes ; Removing an attribute ... A boolean value true will render 'true' , and false will render 'false' ... ariaLabel of...
Read more >Element with aria-hidden has no content in sequential focus ...
Some user agents treat the value of aria-hidden attribute as case-sensitive. Background. Using aria-hidden="false" on a descendant of an element ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I didn’t check out the repro as i don’t have access to dropbox.
But:
false
is the only way to tell Vue to actually remove an attribute - which you may also want to do with an aria attribute in some situtions.aria-checked
values (like all html attribute values) are strings, not booleans:'true'
and'false'
, respectively, so you have to set them as strings:v-bind:aria-checked="checked ? 'true' : 'false'"
I don’t think it makes sense to have aria attributes behave differently than other html attributes in this regard.
Also, we need a way to tell Vue “remove that attribute”, which is setting it to
false
.We’re aware that this works a bit differently than vanilla js:
setAttribute('aria-checked', false)
will set the attribute toaria-checked="false"
. But so will it do forchecked
or any other element:So Vue treats
false
differently, but it does so consistently and for a reason.Vue can’t know which custom attribute of a web component is meant to be a boolean attribute (as opposed to actual HTML attributes wich are defined as being boolean or not ion the spec). So we treat custom attributes as non-boolean attributes.
But: Most Web component implementations sync custom attributes to DOM properties and vice versa (see here).
For web components that do this, the described problem doesn’t really exist, in my experience: When Vue can find a DOM property named
booleanAttribute
(as per your example above), it will use that to set it(el.booleanAttribute = false)
, instead of setting the attribute (el.setAttribute('boolean-attribute', false)
).This way, there is no special treatment necessary - the web component will receive a plain boolean value through the DOM property and can decide how to deal with it (remove the attribute, or set it with a stringified value) according to how it defined that property’s type.
You seem to be using a web component implementation that doesn’t do this, which is unfortunate for for this specific case.