Closed pdesoyres-cc closed 1 year ago
Thanks for this awesome issue :wink:
I would go with option 2 because I like to manipulate this stuff through HTML attributes, especially for atomic components. I'm not against option 3. I think option 1 is too risky.
So for me 2 > 3 > 1.
About the solution 2: I remember suggesting accessible-
as prefix but I'm not sure it's the best idea cause it sounds weird accessible-expanded
/ accessible-selected
etc.
If you have better ideas, please go for it :rocket:
@florian-sanders-cc what do you think of cc-aria-
prefix?
@pdesoyres-cc I think it's better than my suggestion but I'm not completely sold, prefixing our own component attributes with cc-
feels redundant (but it also makes sense here?).
Anyway, it's a good suggestion :+1:
Same as @florian-sanders-cc 2 > 3 > 1
:grimacing:
I vote for solution 2 with accessible-
or a11y-
prefix.
I'll go for a11y-
prefix
Context
When designing the
cc-popover
component, we used acc-button
to trigger the floating content display. Making this pattern accessible requires the use of anaria-expanded
attribute.Our first thought was just to put this attribute on the
<cc-button>
element but after looking closer, we discovered that this is not the right way to do it. The element receiving thearia-expanded
must be the focused element (corresponding todocument.activeElement
). In our case, the<cc-button>
element is not the active element (even if it has got afocus()
method). In fact, the active element is the<button>
element inside thecc-button
component.We need something more to make the
cc-popover
accessible: We need to allow thecc-button
to transmit some aria attributes to its inner<button>
element. There is a related issue: #699Solutions
When facing this kind of problem, we need to look a bit further. We need to think of a solution that fits the need of transmitting some aria attributes from a component into an inner element.
After a discussion with Florian, we are able to propose 3 solutions that we will need to discuss with the whole team.
In each solution below, we will consider as an example, that we want to add two aria attributes to the inner
<button>
element of thecc-button
component. Please consider that the solution needs to apply to any other component and to any other aria attributes.Solution 1: Use
aria-X
propertyThis solution consists of adding new reactive properties to the
cc-button
component. It uses the samearia
prefix as the native HTML.Solution 2: Use
accessible-X
propertyThis solution is very close to the previous one. The only difference is that it uses a different prefix:
accessible
. Note that, this prefix is already used on thecc-button
andcc-icon
components for theaccessible-name
property which is transmitted as anaria-label
attribute to an inner element.Solution 3: Use
aria
object propertyThis solution proposes one single
aria
Object property where users can specify multiple aria attributes at once. Note that the homemadearia
lit directive helps a lot!Directive helping us transmit aria attributes
```javascript import { nothing } from 'lit'; import { directive, Directive } from 'lit/directive.js'; class AriaDirective extends Directive { render (value) { return nothing; } update (part, [aria]) { if (aria == null) { return; } Object.entries(aria).forEach(([a, v]) => { if (typeof v === 'boolean') { if (v) { part.element.setAttribute(`aria-${a}`, ''); } else { part.element.removeAttribute(`aria-${a}`); } } else { part.element.setAttribute(`aria-${a}`, `${v}`); } }); } } export const aria = directive(AriaDirective); ```Pros & Cons