require-parent-role
Warns when an element with an explicit role is placed outside its required parent context.
The parent is looked for along the accessibility tree. The content of a template element is not rendered where it is written, and where it is inserted is not known from the markup, so an element at the top of the content has no parent to judge and is not reported. The top of the content of a declarative shadow root (<template shadowrootmode>) is rendered in its host, so its parent is the host. A slot is not an element of the accessibility tree: the parent of an element in the fallback content of a slot, or of a light child that a slot takes, is the parent of the slot. A light child that no slot takes is not rendered, so it has no parent to judge and is not reported. A fragment (<> of JSX, Astro's <Fragment>) and a template that the framework renders away (Vue's <template v-if>, v-else-if, v-else, v-for and v-slot) are not elements of the accessibility tree either: the parent of what is in them is the parent of the fragment or the template. A template that Vue leaves in the tree (one without a directive, or with v-show) is an ordinary element. Where the assignment is not known (manual slot assignment, or a slot of a framework's component), the parent is the host. An element that an aria-owns refers to is a child of the element that refers to it, not of its DOM parent. An aria-owns on a hidden element (hidden, aria-hidden="true" or an inline display: none / visibility: hidden, on it or an ancestor), one that refers to an element hidden from all users (the same without aria-hidden), a later aria-owns that lists an element an earlier one lists, and a reference that is part of a cycle move nothing.
❌ Examples of incorrect code for this rule
<div role="option">item</div>
✅ Examples of correct code for this rule
<div role="listbox"><div role="option">item</div></div>
Interface
{
"require-parent-role": boolean
}
Default Severity
error