LibWeb: Ignore name-required landmark roles which lack accessible names

This change implements the role-checking requirement from the ARIA spec
at https://w3c.github.io/aria/#document-handling_author-errors_roles
that the “form” and “region” roles are required to have accessible
names — and that if they don’t have accessible names as required, UAs
must treat them as if they’d not been specified at all.
This commit is contained in:
sideshowbarker 2024-12-19 23:34:18 +09:00 committed by Sam Atkins
commit ead3af0163
Notes: github-actions[bot] 2025-01-09 14:09:37 +00:00
7 changed files with 151 additions and 0 deletions

View file

@ -130,6 +130,14 @@ Optional<Role> ARIAMixin::role_from_role_attribute_value() const
}
continue;
}
// https://w3c.github.io/aria/#document-handling_author-errors_roles
// Certain landmark roles require names from authors. In situations where an author has not specified names for
// these landmarks, it is considered an authoring error. The user agent MUST treat such elements as if no role
// had been provided. If a valid fallback role had been specified, or if the element had an implicit ARIA role,
// then user agents would continue to expose that role, instead.
if ((role == ARIA::Role::form || role == ARIA::Role::region)
&& to_element()->accessible_name(to_element()->document(), DOM::ShouldComputeRole::No).value().is_empty())
continue;
// 4. Use the first such substring in textual order that matches the name of a non-abstract WAI-ARIA role.
if (!is_abstract_role(*role))
return *role;