Skip to content

Commit

Permalink
[added] button role but no keydown handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanflorence committed Jan 19, 2015
1 parent fabf6cc commit 109bd94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('props', () => {
<span onClick={k} role="button"/>;
});
});

it('requires onKeyDown', () => {
expectWarning(assertions.props.onClick.BUTTON_ROLE_NO_KEYDOWN.msg, () => {
<span onClick={k} role="button"/>;
});
});
});

it('warns without role', () => {
Expand Down
10 changes: 9 additions & 1 deletion lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ exports.props = {
},

BUTTON_ROLE_NO_KEYUP: {
msg: 'You have `role="button"` but did not define an `onKeyUp` handler. Add it, and have the "Space" character do the same thing as an `onClick` handler.',
msg: 'You have `role="button"` but did not define an `onKeyUp` handler. Add it, and have the "Space" key do the same thing as an `onClick` handler.',
test (tagName, props, children) {
return !(props.role === 'button' && !props.onKeyUp);
}
},

BUTTON_ROLE_NO_KEYDOWN: {
msg: 'You have `role="button"` but did not define an `onKeyDown` handler. Add it, and have the "Enter" key do the same thing as an `onClick` handler.',
test (tagName, props, children) {
return !(props.role === 'button' && !props.onKeyUp);
}
}

}
};

Expand Down

0 comments on commit 109bd94

Please sign in to comment.