feat(commons/aria): support ARIA element internals properties#5171
feat(commons/aria): support ARIA element internals properties#5171straker wants to merge 8 commits into
Conversation
WilcoFiers
left a comment
There was a problem hiding this comment.
We need to look at presentational inheritance.
| flatTreeSetup(fixture); | ||
| const node = fixture.querySelector('#target'); | ||
| assert.equal(aria.getRole(node), 'presentation'); | ||
| }); |
There was a problem hiding this comment.
There's another interesting scenario here we didn't talk about:
| }); | |
| it('handles presentation role inheritance on an ElementInternal role', () => { | |
| fixture.innerHTML = | |
| '<ul role="none"><testutils-element with-role="listitem" id="target"></testutils-element></ul>'; | |
| flatTreeSetup(fixture); | |
| const node = fixture.querySelector('#target'); | |
| assert.equal(aria.getRole(node), 'presentation'); | |
| }); | |
| it('does not set presentation role when ElementInternals isn\'t an allowed child', () => { | |
| fixture.innerHTML = | |
| '<ul role="none"><testutils-element with-role="button" id="target"></testutils-element></ul>'; | |
| flatTreeSetup(fixture); | |
| const node = fixture.querySelector('#target'); | |
| assert.equal(aria.getRole(node), 'button'); | |
| }); |
I'm not actually sure this is how it works in practice. But role=none on ul SHOULD set its child listitems to presentational as well. We should test this I think, and maybe raise a case for in WPT if they don't already have one.
There was a problem hiding this comment.
Tried to verify the actual behavior:
getRole returns listitem (and button stays button).
Presentational inheritance is keyed off the HTML tag name (li, td, …) in inheritsPresentationChain, not the computed role, so a testutils-element never matches.
Added two tests documenting this current behavior. Re-keying inheritance off computed role is a broader change (also affects <div role="listitem"> etc.) and a genuine spec/WPT question, so I've split it into a follow-up: #5181.
There was a problem hiding this comment.
Verified actual browser behavior for this exact case. Both Chrome and Firefox leave the custom element as listitem — neither applies presentational inheritance to an internal role (Chrome strips a native <li> to none, Firefox to generic, but both keep the custom element as listitem). So the current tests document the behavior that matches browsers.
This is the same spec-ahead-of-browsers gap as #5162 (internal-role conflict resolution — Chrome/Firefox/Safari/WPT bugs already filed there), so I've folded the follow-up into #5162 and closed #5181 rather than tracking it separately. Let me know if you're good with matching browsers here.
There was a problem hiding this comment.
But role=none on ul SHOULD set its child listitems to presentational as well.
I think ARIA only requires inheritance for (host-language-)required child elements that do not have explicit roles. (Though I spotted some odd phrasing that seems to have been introduced accidentally - I've filed w3c/aria#2832 to clarify.)
(Then again ul > test-element is invalid HTML and its repair is not specified anywhere, I think.)
Custom elements exposing a required-child role via ElementInternals do not inherit a presentational role from an ancestor role=none list, since inheritance is keyed off the HTML tag name. See #5181.
Add consumer-level tests for the reflected ariaLabelledByElements property (precedence over aria-labelledby and aria-label) in arialabelledbyText and labelVirtual. getResolvedRefs already honors the property; this regression- tests the #4943 scenario. Tests adapted from #5187. Co-authored-by: JC Franco <jfranco@esri.com>
Updates the
commons/ariadirectory to use the newgetAriaValue,hasAriaValue, andgetResolvedRefsfunctions where it makes sense.Here's a report of the full directory:
commons/aria/arialabel-text- aria-label → getAriaValuecommons/aria/arialabelledby-text- aria-labelledby:.attr()check → hasAriaValue;idrefs()→ getResolvedRefs; since getResolvedRefs returns VirtualNodes, switchedaccessibleText(elm)toaccessibleTextVirtual(elm)for the direct VirtualNodecommons/aria/get-owned-virtual- aria-owns:.hasAttr()→ hasAriaValue;idrefs(actualNode, ...)+getNodeFromTree()→ getResolvedRefs (already returns VirtualNodes, so getNodeFromTree is no longer needed)commons/aria/label-virtual- aria-labelledby:.attr()check → hasAriaValue;idrefs()+getNodeFromTree()→ getResolvedRefs; aria-label → getAriaValuecommons/aria/validate-attr-value- validates attrs, no conversion at this timecommons/aria/get-accessible-refs- usesnode.hasAttribute('for')on raw DOM node for HTMLforattribute, not an ARIA propcommons/aria/get-aria-value- this is the new function being adoptedcommons/aria/get-element-unallowed-roles- checksroleattribute, not an ARIA propcommons/aria/get-role- matching browser support and not using internals global attrs to check for role resolution, and also not running implicit role for role resolution if it's a custom elementcommons/aria/has-aria-value- this is the new function being adoptedcommons/aria/lookup-table- deprecatedcommons/aria/allowed-attr/get-explicit-role/get-role-type/get-roles-by-type/get-roles-with-name-from-contents/implicit-role/implicit-nodes/is-accessible-ref/is-aria-role-allowed-on-element/is-combobox-popup/is-unsupported-role/is-valid-role/label/named-from-contents/required-attr/required-context/required-owned/validate-attr- no ARIA attr value accessCloses: #5140