UNPKG

@markuplint/ml-spec

Version:

Types and schema that specs of the Markup languages for markuplint

25 lines (24 loc) 897 B
import { isPresentational } from '../specs/is-presentational.js'; import { getComputedRole } from './get-computed-role.js'; export function getNonPresentationalAncestor( // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types el, specs, version) { let ancestor = el.parentElement; /** * In ARIA 1.1 and 1.2, the role of an element is not affected by the role of its ancestor elements. * * It is due to implementation considerations in Markuplint. */ const assumeSingleNode = version !== '1.1' && version !== '1.2'; while (ancestor) { const ancestorRole = getComputedRole(specs, ancestor, version, assumeSingleNode); if (!isPresentational(ancestorRole.role?.name)) { return ancestorRole; } ancestor = ancestor.parentElement; } return { el: ancestor, role: null, }; }