GithubHelp home page GithubHelp logo

willcode2surf / react-a11y Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reactjs/react-a11y

0.0 2.0 0.0 94 KB

Identifies accessibility issues in your React.js elements

License: MIT License

JavaScript 99.79% Shell 0.21%

react-a11y's Introduction

React A11y

build status

Warns about potential accessibility issues with your React elements.

screenshot

WIP

This is a WIP, feel free to explore, open issues, and suggest assertions :)

Installation

npm install react-a11y

Usage

In your main application file, require and call the module, you'll start getting warnings in the console as your app renders.

var a11y = require('react-a11y');
if (ENV === 'development') a11y(React);

You probably don't want to call it if you're in production, and better yet, alias the module to nothing with webpack in production.

If you want it to throw errors instead of just warnings:

a11y(React, { throw: true });

You can filter failures by passing a function to the filterFn option. The filter function will receive three arguments: the name of the Component instance or ReactElement, the id of the element, and the failure message. Note: If a ReactElement, the name will be the node type followed by the id (e.g. div#foo).

var commentListFailures = (name, id, msg) => {
  return name === "CommentList";
};

a11y(React, { filterFn: commentListFailures });

If you want to log DOM element references for easy lookups in the DOM inspector, use the includeSrcNode option.

a11y(React, { throw: true, includeSrcNode: true });

Some test are only relevant for certain device types. For example, if you are building a mobile web app, you can filter out desktop-specific rules by specifying a specific device type:

a11y(React, { device: ['mobile'] });

It's also possible exclude certain tests:

a11y(React, { exclude: ['REDUNDANT_ALT'] });

ReactDOM

You should pass ReactDOM to a11y for React >= 0.14 compatibility.

a11y(React, { ReactDOM: ReactDOM });

Cleaning Up In Tests

Use the restoreAll() method to clean up mutations made to React. Useful if you are using React-a11y in your test suite.

beforeEach(() => a11y(React));
afterEach(() => a11y.restoreAll());

react-a11y's People

Contributors

alexlande avatar angus-c avatar asaayers avatar coreykumpal avatar kloots avatar matt-royal avatar mrfr0g avatar robdel12 avatar ryanflorence avatar swaagie avatar wyattdanger avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.