Skip to content

Commit c5866fa

Browse files
committed
fix: unwrap mustache string literals in type attribute check
1 parent 722521e commit c5866fa

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/rules/template-no-aria-hidden-on-focusable.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
'use strict';
22

33
const { isNativeElement } = require('../utils/is-native-element');
4+
const { getStaticAttrValue } = require('../utils/static-attr-value');
45

56
function findAttr(node, name) {
67
return node.attributes?.find((a) => a.name === name);
78
}
89

10+
// Returns the statically-known string value of a named attribute, or
11+
// `undefined` when the attribute is absent or its value is dynamic.
912
function getTextAttrValue(node, name) {
1013
const attr = findAttr(node, name);
11-
if (attr?.value?.type === 'GlimmerTextNode') {
12-
return attr.value.chars;
14+
if (!attr) {
15+
return undefined;
1316
}
14-
return undefined;
17+
return getStaticAttrValue(attr.value);
1518
}
1619

1720
// Per WAI-ARIA 1.2 §6.6 + aria-hidden value table, a missing or empty-string

tests/lib/rules/template-no-aria-hidden-on-focusable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ ruleTester.run('template-no-aria-hidden-on-focusable', rule, {
3131

3232
// <input type="hidden"> isn't focusable, so aria-hidden on it is fine.
3333
'<template><input type="hidden" aria-hidden="true" /></template>',
34+
// Mustache string literal — statically resolvable to "hidden".
35+
'<template><input type={{"hidden"}} aria-hidden="true" /></template>',
3436

3537
// <a> without href isn't focusable by default.
3638
'<template><a aria-hidden="true">Not a link</a></template>',
@@ -204,6 +206,8 @@ hbsRuleTester.run('template-no-aria-hidden-on-focusable', rule, {
204206
'<div aria-hidden="true"></div>',
205207
'<button>Click me</button>',
206208
'<input type="hidden" aria-hidden="true" />',
209+
// Mustache string literal — statically resolvable to "hidden".
210+
'<input type={{"hidden"}} aria-hidden="true" />',
207211
'<CustomBtn aria-hidden="true" />',
208212
// Descendant-focusable — non-focusable child.
209213
'<div aria-hidden="true"><span>Just text</span></div>',

0 commit comments

Comments
 (0)