Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

react-a11y-no-onchange: Allow onChange when onBlur is present (#836) #854

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/reactA11yNoOnchangeRule.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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