Skip to content

Commit 109bd94

Browse files
committed
[added] button role but no keydown handler
1 parent fabf6cc commit 109bd94

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/__tests__/index-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ describe('props', () => {
6666
<span onClick={k} role="button"/>;
6767
});
6868
});
69+
70+
it('requires onKeyDown', () => {
71+
expectWarning(assertions.props.onClick.BUTTON_ROLE_NO_KEYDOWN.msg, () => {
72+
<span onClick={k} role="button"/>;
73+
});
74+
});
6975
});
7076

7177
it('warns without role', () => {

lib/assertions.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,19 @@ exports.props = {
116116
},
117117

118118
BUTTON_ROLE_NO_KEYUP: {
119-
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.',
119+
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.',
120+
test (tagName, props, children) {
121+
return !(props.role === 'button' && !props.onKeyUp);
122+
}
123+
},
124+
125+
BUTTON_ROLE_NO_KEYDOWN: {
126+
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.',
120127
test (tagName, props, children) {
121128
return !(props.role === 'button' && !props.onKeyUp);
122129
}
123130
}
131+
124132
}
125133
};
126134

0 commit comments

Comments
 (0)