diff --git a/src/reactA11yNoOnchangeRule.ts b/src/reactA11yNoOnchangeRule.ts index cf8fd449b..a24da1743 100644 --- a/src/reactA11yNoOnchangeRule.ts +++ b/src/reactA11yNoOnchangeRule.ts @@ -59,7 +59,7 @@ function walk(ctx: Lint.WalkContext) { } 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); } diff --git a/src/tests/ReactA11yNoOnchangeRuleTests.ts b/src/tests/ReactA11yNoOnchangeRuleTests.ts index 77f7663e7..5d6a64ed9 100644 --- a/src/tests/ReactA11yNoOnchangeRuleTests.ts +++ b/src/tests/ReactA11yNoOnchangeRuleTests.ts @@ -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 =