123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { getExplicitRole, getRole } from '../../commons/aria';
- import { getGlobalAriaAttrs } from '../../commons/standards';
- import { isFocusable } from '../../commons/dom';
- function presentationalRoleEvaluate(node, options, virtualNode) {
- const role = getRole(virtualNode);
- const explicitRole = getExplicitRole(virtualNode);
- if (['presentation', 'none'].includes(role)) {
- this.data({ role });
- return true;
- }
- // if the user didn't intended to make this presentational we fail
- if (!['presentation', 'none'].includes(explicitRole)) {
- return false;
- }
- // user intended to make this presentational so inform them of
- // problems caused by role conflict resolution
- const hasGlobalAria = getGlobalAriaAttrs().some(attr =>
- virtualNode.hasAttr(attr)
- );
- const focusable = isFocusable(virtualNode);
- let messageKey;
- if (hasGlobalAria && !focusable) {
- messageKey = 'globalAria';
- } else if (!hasGlobalAria && focusable) {
- messageKey = 'focusable';
- } else {
- messageKey = 'both';
- }
- this.data({
- messageKey,
- role
- });
- return false;
- }
- export default presentationalRoleEvaluate;
|