OAA WIDGET_11: Check that non-form and non-anchor elements with event handlers have valid roles.

Details

  • Check that non-form and non-anchor elements with event handlers have valid roles.

Rulesets

WCAG 2.0 Requirement 2.1.1 Keyboard
Status: Accepted
Severity: Violation
Priority: Priority 1
IITAA 1.0 13.2 Ensure that significant interactions can be performed with both keyboard and mouse.
Type:
Severity: Violation
Priority: Priority 1
Status: Accepted

Markup References

Validation Code

Message

A non-form (e.g. input, button, select and textarea elements) or non-anchor element (e.g. 'a' element) has a onKeyXXX, onMouseXXX or onClick event handler and does not have a role attribute or the role value is not a valid ARIA role value.

Dependencies

None

Context

.nonfocusableElementsContainingEvents

Parameters

None

Code


   function (ruleContext) {
      var passed = true;
      /*SMF TODO the following should be taken care of in the context */
      if (ruleContext.nodeName.toLowerCase() == "a" && OpenAjax.a11y.xbrowser.hasAttribute(ruleContext, 'href')) return new ValidationResult(passed, [ruleContext], '', '', []);
      if (ruleContext.nodeName.toLowerCase() == "area" && OpenAjax.a11y.xbrowser.hasAttribute(ruleContext, 'href')) return new ValidationResult(passed, [ruleContext], '', '', []);
      
      var events = util.getEvents(ruleContext);
      if (events.length > 0) {
         function hasEvent(a) {
            if (OpenAjax.a11y.xbrowser.indexOf(events, ('on' + a)) != -1) return 'on' + a;  
            if (OpenAjax.a11y.xbrowser.indexOf(events, a) != -1) return a;
            return '';
         }
         function hasTargetEvent() {
            var found = false;
            var _targetEvents=new Array("click","keyup","keydown","keypress", "mousedown","mouseup","mousemove","mouseout","mouseover");
            for (i = 0; i < _targetEvents.length && !found; i ++) {
               found = hasEvent(_targetEvents[i]);
               if (!found) found = hasEvent(_targetEvents[i]);
            }
            return found;
         }
         passed = !hasTargetEvent();
      }
      return new ValidationResult(passed, [ruleContext], '', '', []);
   }