Skip to content

Commit d0844e1

Browse files
committed
fix: apply <dialog> exemption to mustache form + update comment (Copilot review)
1 parent 6d4fcda commit d0844e1

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

lib/rules/template-no-autofocus-attribute.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
* boolean-attribute semantics. vue-a11y and lit-a11y are presence-based,
1010
* consistent with the spec. We follow the spec.
1111
*
12-
* The only exception is a mustache boolean-literal `{{false}}` in element
13-
* syntax — Glimmer authors writing `autofocus={{false}}` are expressing
14-
* intent to omit the attribute conditionally. Treat that narrow literal
15-
* case as opt-out (the rendered HTML will have no autofocus attr).
12+
* The only exception is a boolean-literal `false` — in element syntax
13+
* written as `autofocus={{false}}`, and in mustache hash syntax written as
14+
* `{{input autofocus=false}}`. Both forms express intent to omit the
15+
* attribute conditionally, and the rendered HTML will have no autofocus
16+
* attribute. Treat both literal-false cases as opt-out.
1617
*
1718
* Verified against Glimmer VM's attribute-normalization source:
1819
* glimmer-vm/packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts —
@@ -135,6 +136,12 @@ module.exports = {
135136
return;
136137
}
137138

139+
// MDN dialog exception: autofocus on a mustache component/helper
140+
// nested inside a <dialog> is recommended behavior, not a defect.
141+
if (isInsideDialog(node)) {
142+
return;
143+
}
144+
138145
context.report({
139146
node: autofocusPair,
140147
messageId: 'noAutofocus',

tests/lib/rules/template-no-autofocus-attribute.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ ruleTester.run('template-no-autofocus-attribute', rule, {
4848
</div>
4949
</dialog>
5050
</template>`,
51+
// Dialog exception also applies to the mustache form of the `<Input>`
52+
// helper (`{{input autofocus=true}}`) — whether direct child or nested.
53+
`<template>
54+
<dialog>
55+
{{input autofocus=true}}
56+
</dialog>
57+
</template>`,
58+
`<template>
59+
<dialog>
60+
<div>
61+
{{input autofocus=true}}
62+
</div>
63+
</dialog>
64+
</template>`,
5165
],
5266

5367
invalid: [

0 commit comments

Comments
 (0)