@@ -6,52 +6,53 @@ import {
66} from '../util' ;
77
88export default {
9- msg : 'You have `role="button"` but did not define an `onKeyDown` or `onKeyPress` handler. '
9+ msg : 'You have an `onClick` handler but did not define an `onKeyDown`, `onKeyUp ` or `onKeyPress` handler. '
1010 + 'Add it, and have the "Space" key do the same thing as an `onClick` handler.' ,
1111 url : 'https://www.w3.org/WAI/GL/wiki/Making_actions_keyboard_accessible_by_using_keyboard_event_handlers_with_WAI-ARIA_controls' ,
1212 affects : [
1313 devices . keyboardOnly
1414 ] ,
1515 test ( tagName , props ) {
1616 const hidden = hiddenFromAT ( props ) ;
17- const button = props . role === 'button' ;
17+ const onClick = listensTo ( props , 'onClick' ) ;
1818 const onKeyDown = listensTo ( props , 'onKeyDown' ) ;
19+ const onKeyUp = listensTo ( props , 'onKeyUp' ) ;
1920 const onKeyPress = listensTo ( props , 'onKeyPress' ) ;
2021
2122 // rule passes when element is hidden,
22- // has role='button' and has an onKeyDown or onKeyPress prop
23- return hidden || ! button || onKeyDown || onKeyPress ;
23+ // has onClick and has an onKeyDown, onKeyUp or onKeyPress prop
24+ return hidden || ! onClick || onKeyDown || onKeyUp || onKeyPress ;
2425 }
2526} ;
2627
2728export const pass = [ {
28- when : 'role="button" but there is an onKeyDown handler.' ,
29+ when : 'there is an onClick handler and there is an onKeyDown handler.' ,
2930 // eslint-disable-next-line jsx-a11y/no-static-element-interactions
30- render : React => < div role = "button" onKeyDown = { fn } />
31+ render : React => < div onClick = { fn } onKeyDown = { fn } />
3132} , {
32- when : 'role="button" but there is an onKeyPress handler.' ,
33+ when : 'there is an onClick handler and there is an onKeyUp handler.' ,
3334 // eslint-disable-next-line jsx-a11y/no-static-element-interactions
34- render : React => < div role = "button" onKeyPress = { fn } />
35+ render : React => < div onClick = { fn } onKeyUp = { fn } />
3536} , {
36- when : 'there is no role' ,
37- render : React => < div > derp</ div >
37+ when : 'there is an onClick handler and there is an onKeyPress handler.' ,
38+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
39+ render : React => < div onClick = { fn } onKeyPress = { fn } />
3840} , {
39- when : 'there the role is not button' ,
40- // eslint-disable-next-line jsx-a11y/aria-role
41- render : React => < div role = "foo" />
41+ when : 'there is no onClick' ,
42+ render : React => < div > derp</ div >
4243} , {
4344 when : 'the element is aria-hidden' ,
4445 render : React => < div aria-hidden role = "button" />
4546} ] ;
4647
4748export const fail = [ {
48- when : 'role="button" and no `onKeyDown` or `onKeyPress` is present' ,
49- render : React => < div role = "button" />
49+ when : 'there is an onClick handler but no `onKeyDown`, `onKeyUp ` or `onKeyPress` is present' ,
50+ render : React => < div onClick = { fn } />
5051} ] ;
5152
5253export const description = `
5354Enforce that elements which have the \`role="button"\`
5455also have an \`onKeyDown\` or \`onKeyPress\` handler that handles Space or Enter
55- (this is isn't actually checked) for poeple that are using a
56+ (this is isn't actually checked) for people that are using a
5657keyboard-only device.
5758` ;
0 commit comments