diff --git a/lib/__tests__/index-test.js b/lib/__tests__/index-test.js index a3adc2f..4c684ef 100644 --- a/lib/__tests__/index-test.js +++ b/lib/__tests__/index-test.js @@ -89,7 +89,7 @@ describe('props', () => {
; }); }); - + it('warns if there is an image with an empty alt attribute', () => { expectWarning(assertions.props.onClick.NO_LABEL.msg, () => { ; @@ -99,13 +99,13 @@ describe('props', () => { describe('when role="button"', () => { it('requires onKeyUp', () => { - expectWarning(assertions.props.onClick.BUTTON_ROLE_NO_KEYUP.msg, () => { + expectWarning(assertions.props.onClick.BUTTON_ROLE_SPACE.msg, () => { ; }); }); it('requires onKeyDown', () => { - expectWarning(assertions.props.onClick.BUTTON_ROLE_NO_KEYDOWN.msg, () => { + expectWarning(assertions.props.onClick.BUTTON_ROLE_ENTER.msg, () => { ; }); }); diff --git a/lib/assertions.js b/lib/assertions.js index 223861f..3adede5 100644 --- a/lib/assertions.js +++ b/lib/assertions.js @@ -68,17 +68,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" key do the same thing as an `onClick` handler.', + // onKeyUp is too late to cancel space's default behavior of scrolling the + // page. + BUTTON_ROLE_SPACE: { + msg: 'You have `role="button"` but did not define an `onKeyDown` 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); + return !(props.role === 'button' && !props.onKeyDown); } }, - BUTTON_ROLE_NO_KEYDOWN: { + BUTTON_ROLE_ENTER: { 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); + return !(props.role === 'button' && props.onKeyDown); } }