diff --git a/Libraries/LibWeb/HTML/HTMLLIElement.h b/Libraries/LibWeb/HTML/HTMLLIElement.h
index d03e391104f..362b162dcdc 100644
--- a/Libraries/LibWeb/HTML/HTMLLIElement.h
+++ b/Libraries/LibWeb/HTML/HTMLLIElement.h
@@ -6,8 +6,10 @@
#pragma once
-#include
+#include
#include
+#include
+#include
#include
namespace Web::HTML {
@@ -20,7 +22,18 @@ public:
virtual ~HTMLLIElement() override;
// https://www.w3.org/TR/html-aria/#el-li
- virtual Optional default_role() const override { return ARIA::Role::listitem; }
+ virtual Optional default_role() const override
+ {
+ for (auto const* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) {
+ if (ancestor->role_or_default() == ARIA::Role::list)
+ return ARIA::Role::listitem;
+ }
+ // https://w3c.github.io/core-aam/#roleMappingComputedRole
+ // When an element has a role but is not contained in the required context (for example, an orphaned listitem
+ // without the required accessible parent of role list), User Agents MUST ignore the role token, and return the
+ // computedrole as if the ignored role token had not been included.
+ return ARIA::Role::none;
+ }
WebIDL::Long value();
void set_value(WebIDL::Long value)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt
new file mode 100644
index 00000000000..43ee599a269
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html-aam/roles-generic.tentative.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass el-li-orphaned
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html
new file mode 100644
index 00000000000..150ea5a9ae1
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html-aam/roles-generic.tentative.html
@@ -0,0 +1,21 @@
+
+
+
+ Tentative: HTML-AAM Generic Role Verification Tests
+
+
+
+
+
+
+
+
+
+x
+
+
+
+
+
\ No newline at end of file