Skip to content

Commit

Permalink
feat: added new custom rule sa11y-Keyboard-button (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaig-0911 authored Nov 8, 2024
1 parent 3a71ac1 commit 10067c9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/preset-rules/src/custom-rules/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ const checkData = [
},
},
},
{
id: 'sa11y-Keyboard-button-check',
evaluate:
"function (node) { const tabIndex = node.getAttribute('tabindex'); if ( tabIndex === '-1' && node.actualNode && !isVisibleOnScreen(node) && !isVisibleToScreenReaders(node)) { return false; } if(!node.innerText ===\"\"){ return false; } if(!node.hasAttribute('tabindex')){ return false; } return true; }",
messages: {
pass: 'Button element are keyboard operable',
fail: "Button element are not keyboard operable, To fix add tabindex='0' attribute and appropriate keyboard event handler.",
},
},
];

export default checkData as axe.Check[];
18 changes: 18 additions & 0 deletions packages/preset-rules/src/custom-rules/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ const rulesData = [
tags: ['wcag1410', 'custom'],
},
},
{
id: 'sa11y-Keyboard-button',
selector:
"[role='button']:not(a[href],button,input,select,area[href],textarea,[contentEditable=true],[disabled],details)",
enabled: true,
any: ['sa11y-Keyboard-button-check'],
all: [],
metadata: {
description: 'Element is not keyboard operable',
help: "Fix any one of the following :\n \
1.The button element missing keyboard operability. To fix add tabindex='0' attribute and appropriate keyboard event handler.\n \
2.Remove role='button' attribute",
helpUrl: '',

impact: 'critical',
tags: ['wcag211', 'custom'],
},
},
];

export default rulesData as axe.Rule[];

0 comments on commit 10067c9

Please sign in to comment.