Skip to content

Commit 7165f51

Browse files
committed
Fix template-require-aria-activedescendant-tabindex: autofix insertion for non-div tags
Replaces hardcoded '<div'.length with computed offset based on the actual tag name. Previous code mis-positioned the tabindex insertion on <a>, <button>, and other non-3-char tags.
1 parent 56f913d commit 7165f51

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/rules/template-require-aria-activedescendant-tabindex.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ module.exports = {
103103
return fixer.insertTextAfterRange(lastAttribute.range, ` ${FIXED_TABINDEX}`);
104104
}
105105

106-
const insertPos = node.parts.at(-1)?.range[1] ?? node.range[0] + '<div'.length;
106+
const insertPos =
107+
node.parts.at(-1)?.range[1] ?? node.range[0] + 1 + node.tag.length;
107108
return fixer.insertTextAfterRange([insertPos, insertPos], ` ${FIXED_TABINDEX}`);
108109
}
109110

tests/lib/rules/template-require-aria-activedescendant-tabindex.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ const invalidHbs = [
3636
output: '<div aria-activedescendant="fixme" tabindex="0"></div>',
3737
errors: [{ message: ERROR_MESSAGE }],
3838
},
39+
{
40+
code: '<a aria-activedescendant="x"></a>',
41+
output: '<a aria-activedescendant="x" tabindex="0"></a>',
42+
errors: [{ message: ERROR_MESSAGE }],
43+
},
44+
{
45+
code: '<button aria-activedescendant="x" tabindex="-1"></button>',
46+
output: '<button aria-activedescendant="x" tabindex="0"></button>',
47+
errors: [{ message: ERROR_MESSAGE }],
48+
},
3949
];
4050

4151
function wrapTemplate(entry) {

0 commit comments

Comments
 (0)