How to use aria-query - 10 common examples

To help you get started, we’ve selected a few aria-query examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / rules / role-has-required-aria-props.js View on Github external
JSXAttribute: function JSXAttribute(attribute) {
        var name = (0, _jsxAstUtils.propName)(attribute).toLowerCase();

        if (name !== 'role') {
          return;
        }

        var type = (0, _jsxAstUtils.elementType)(attribute.parent);

        if (!_ariaQuery.dom.get(type)) {
          return;
        }

        var roleAttrValue = (0, _jsxAstUtils.getLiteralPropValue)(attribute);
        var attributes = attribute.parent.attributes; // If value is undefined, then the role attribute will be dropped in the DOM.
        // If value is null, then getLiteralAttributeValue is telling us
        // that the value isn't in the form of a literal.

        if (roleAttrValue === undefined || roleAttrValue === null) {
          return;
        }

        var normalizedValues = String(roleAttrValue).toLowerCase().split(' ');
        var validRoles = normalizedValues.filter(function (val) {
          return (0, _toConsumableArray2["default"])(_ariaQuery.roles.keys()).indexOf(val) > -1;
        }); // Check semantic DOM elements
github claykohut / ethtxt / node_modules / eslint-plugin-jsx-a11y / lib / rules / role-has-required-aria-props.js View on Github external
JSXAttribute: function JSXAttribute(attribute) {
        var name = (0, _jsxAstUtils.propName)(attribute).toLowerCase();

        if (name !== 'role') {
          return;
        }

        var type = (0, _jsxAstUtils.elementType)(attribute.parent);
        if (!_ariaQuery.dom.get(type)) {
          return;
        }

        var value = (0, _jsxAstUtils.getLiteralPropValue)(attribute);

        // If value is undefined, then the role attribute will be dropped in the DOM.
        // If value is null, then getLiteralAttributeValue is telling us
        // that the value isn't in the form of a literal.
        if (value === undefined || value === null) {
          return;
        }

        var normalizedValues = String(value).toLowerCase().split(' ');
        var validRoles = normalizedValues.filter(function (val) {
          return [].concat(_toConsumableArray(_ariaQuery.roles.keys())).indexOf(val) > -1;
        });
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / util / isInteractiveRole.js View on Github external
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _ariaQuery = require("aria-query");

var _jsxAstUtils = require("jsx-ast-utils");

var _arrayIncludes = _interopRequireDefault(require("array-includes"));

var roles = (0, _toConsumableArray2["default"])(_ariaQuery.roles.keys());
var interactiveRoles = roles.filter(function (name) {
  return !_ariaQuery.roles.get(name)["abstract"];
}).filter(function (name) {
  return _ariaQuery.roles.get(name).superClass.some(function (klasses) {
    return (0, _arrayIncludes["default"])(klasses, 'widget');
  });
}); // 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.

interactiveRoles.push('toolbar');
/**
 * Returns boolean indicating whether the given element has a role
 * that is associated with an interactive component. Used when an element
 * has a dynamic handler on it and we need to discern whether or not
 * its intention is to be interacted with in the DOM.
 *
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / util / isInteractiveRole.js View on Github external
}).filter(function (name) {
  return _ariaQuery.roles.get(name).superClass.some(function (klasses) {
    return (0, _arrayIncludes["default"])(klasses, 'widget');
  });
}); // 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / util / isInteractiveElement.js View on Github external
exports["default"] = void 0;

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _ariaQuery = require("aria-query");

var _axobjectQuery = require("axobject-query");

var _arrayIncludes = _interopRequireDefault(require("array-includes"));

var _attributesComparator = _interopRequireDefault(require("./attributesComparator"));

var domKeys = (0, _toConsumableArray2["default"])(_ariaQuery.dom.keys());
var roleKeys = (0, _toConsumableArray2["default"])(_ariaQuery.roles.keys());
var elementRoleEntries = (0, _toConsumableArray2["default"])(_ariaQuery.elementRoles);
var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
  var role = _ariaQuery.roles.get(name);

  return !role["abstract"] && !role.superClass.some(function (classes) {
    return (0, _arrayIncludes["default"])(classes, 'widget');
  });
}));
var interactiveRoles = new Set([].concat(roleKeys, // 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
'toolbar').filter(function (name) {
  var role = _ariaQuery.roles.get(name);

  return !role["abstract"] && role.superClass.some(function (classes) {
    return (0, _arrayIncludes["default"])(classes, 'widget');
  });
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / rules / role-supports-aria-props.js View on Github external
JSXOpeningElement: function JSXOpeningElement(node) {
        // If role is not explicitly defined, then try and get its implicit role.
        var type = (0, _jsxAstUtils.elementType)(node);
        var role = (0, _jsxAstUtils.getProp)(node.attributes, 'role');
        var roleValue = role ? (0, _jsxAstUtils.getLiteralPropValue)(role) : (0, _getImplicitRole["default"])(type, node.attributes);
        var isImplicit = roleValue && role === undefined; // If there is no explicit or implicit role, then assume that the element
        // can handle the global set of aria-* properties.
        // This actually isn't true - should fix in future release.

        if (typeof roleValue !== 'string' || _ariaQuery.roles.get(roleValue) === undefined) {
          return;
        } // Make sure it has no aria-* properties defined outside of its property set.


        var _roles$get = _ariaQuery.roles.get(roleValue),
            propKeyValues = _roles$get.props;

        var propertySet = Object.keys(propKeyValues);
        var invalidAriaPropsForRole = (0, _toConsumableArray2["default"])(_ariaQuery.aria.keys()).filter(function (attribute) {
          return propertySet.indexOf(attribute) === -1;
        });
        node.attributes.forEach(function (prop) {
          // Ignore the attribute if its value is null or undefined.
          if ((0, _jsxAstUtils.getPropValue)(prop) == null) return; // Ignore the attribute if it's a spread.

          if (prop.type === 'JSXSpreadAttribute') return;
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / rules / role-has-required-aria-props.js View on Github external
var validRoles = normalizedValues.filter(function (val) {
          return (0, _toConsumableArray2["default"])(_ariaQuery.roles.keys()).indexOf(val) > -1;
        }); // Check semantic DOM elements
        // For example, <input role="switch" type="checkbox">
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / util / isInteractiveElement.js View on Github external
var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
  var role = _ariaQuery.roles.get(name);

  return !role["abstract"] && !role.superClass.some(function (classes) {
    return (0, _arrayIncludes["default"])(classes, 'widget');
  });
}));
var interactiveRoles = new Set([].concat(roleKeys, // 'toolbar' does not descend from widget, but it does support
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / rules / click-events-have-key-events.js View on Github external
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));

var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));

var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));

/**
 * @fileoverview Enforce a clickable non-interactive element has at least 1 keyboard event listener.
 * @author Ethan Cohen
 */
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Visible, non-interactive elements with click handlers must have at least one keyboard listener.';
var schema = (0, _schemas.generateObjSchema)();
var domElements = (0, _toConsumableArray2["default"])(_ariaQuery.dom.keys());
module.exports = {
  meta: {
    docs: {
      url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/click-events-have-key-events.md'
    },
    schema: [schema]
  },
  create: function create(context) {
    return {
      JSXOpeningElement: function JSXOpeningElement(node) {
        var props = node.attributes;

        if ((0, _jsxAstUtils.getProp)(props, 'onclick') === undefined) {
          return;
        }
github makuga01 / dnsFookup / FE / node_modules / eslint-plugin-jsx-a11y / lib / rules / scope.js View on Github external
JSXAttribute: function JSXAttribute(node) {
        var name = (0, _jsxAstUtils.propName)(node);

        if (name && name.toUpperCase() !== 'SCOPE') {
          return;
        }

        var parent = node.parent;
        var tagName = (0, _jsxAstUtils.elementType)(parent); // Do not test higher level JSX components, as we do not know what
        // low-level DOM element this maps to.

        if (!_ariaQuery.dom.has(tagName)) {
          return;
        }

        if (tagName && tagName.toUpperCase() === 'TH') {
          return;
        }

        context.report({
          node,
          message: errorMessage
        });
      }
    };