Skip to content

Commit

Permalink
Allow onChange when onBlur is present (microsoft#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
soon committed Apr 2, 2019
1 parent e92a08f commit 517de21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reactA11yNoOnchangeRule.ts
Expand Up @@ -59,7 +59,7 @@ function walk(ctx: Lint.WalkContext<Options>) {
}

const attributes = getJsxAttributesFromJsxElement(node);
if (attributes.hasOwnProperty('onchange')) {
if (attributes.hasOwnProperty('onchange') && !attributes.hasOwnProperty('onblur')) {
const errorMessage = `onChange event handler should not be used with the <${tagName}>. Please use onBlur instead.`;
ctx.addFailureAt(node.getStart(), node.getWidth(), errorMessage);
}
Expand Down
9 changes: 9 additions & 0 deletions src/tests/ReactA11yNoOnchangeRuleTests.ts
Expand Up @@ -35,6 +35,15 @@ describe('reactA11yNoOnchangeRule', (): void => {
]);
});

it('should not fail if select element attributes contains onBlur event even if it also contains onChange event', (): void => {
const script: string = `
import React = require('react');
const selectElementWithOnChange = <select onChange={} onBlur={} />\`;
`;

TestHelper.assertNoViolation(ruleName, script);
});

it('should fail if additional tag name specified in options contains onChange event', () => {
const script: string = `
import React = require('react');
Expand Down

0 comments on commit 517de21

Please sign in to comment.