[Proposal]: Enable HTMLElement
attributes to be toggled without JavaScript
#10357
Labels
addition/proposal
New features or enhancements
needs implementer interest
Moving the issue forward requires implementers to express interest
What problem are you trying to solve?
It's common for applications to create content that can be accessibly expanded/collapsed with the
aria-expanded
attribute. Unfortunately, there is no native way to toggle this attribute without JavaScript today. Consequently, there are several rich user experiences that are currently unaccessible to people without JavaScript.With the power of CSS selectors (especially now that we have
:has()
on the scene), we can pretty much "expand" any element with just CSS. Below is a simple example:So all that we really need in order to make elements expandable without JS is a feature that would enable an attribute to be toggled without JS. It would be spectacular if that could be supported! 🙏🏾
What solutions exist today?
Bad: Navigation
One existing solution is to create a link that acts like an expandable button by navigating to a URL where the content is already expanded.
However, this approach has a few significant problems:
Slightly Better but Limited: Hacking the
<details>
ElementTheoretically, now that we have
:has()
, it would be possible to hack the<details>
element to accomplish the desired behavior witharia-owns
in the event that the content does not visually live inside the<details>
element.Then the CSS would potentially look something like this:
This is significantly more preferable than awkwardly chatting with the server, but this approach still has other significant caveats:
(Edit: It looks like VoiceOver very recently got support for this attribute.)aria-owns
is not supported by VoiceOver.How would you solve it?
The Popover API seems like a potential source of inspiration. HTML attributes could be used to determine how an element's attributes should be changed when a button is clicked.
This is just one potential solution. I'm certain there are other alternatives.
Anything else?
Multiple Buttons Expanding/Collapsing the Same Element
There might be situations where multiple elements on the same page would be able to control the same element's visibility. In that case, there would need to be a way to "link" all of them together. I'm not sure what a good solution would look like. But off the top of my head, one potential idea is to use another attribute that can group together a set of controls (just like radio buttons are grouped by
name
).Doing More Than Attribute Toggling
It's possible that what's really surfacing from this feature proposal is a way to control attributes without JavaScript in a more broad sense. However, I'm not immediately certain what the use cases for that would be. It's just a thought.
The text was updated successfully, but these errors were encountered: