Skip to content

Commit 62d7049

Browse files
committed
refactor: align with #37's HTML-content-model authority split
Replace lib/utils/native-interactive-elements.js with lib/utils/html-interactive-content.js to match the canonical util introduced in #37. The new util cites HTML Living Standard §3.2.5.2.7 Interactive Content as its sole authority, resolving the previous mixed-authority approach that cited axobject-query's widget taxonomy for some rows and HTML spec for others. Byte-identical copy of #37's util + test across worktrees so the two PRs can land in either order without conflict.
1 parent 30a5f0b commit 62d7049

5 files changed

Lines changed: 18 additions & 272 deletions

lib/rules/template-click-events-have-key-events.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { dom } = require('aria-query');
22
const { isComponentInvocation } = require('../utils/is-component-invocation');
3-
const { isNativeInteractive } = require('../utils/native-interactive-elements');
3+
const { isHtmlInteractiveContent } = require('../utils/html-interactive-content');
44

55
const KEYBOARD_EVENT_NAMES = new Set(['keydown', 'keyup', 'keypress']);
66

@@ -15,7 +15,7 @@ function getAttrTextValue(attr) {
1515
return undefined;
1616
}
1717

18-
// Adapter matching the `isNativeInteractive` util's expected signature:
18+
// Adapter matching the `isHtmlInteractiveContent` util's expected signature:
1919
// `(node, attrName) -> string | undefined` for static attribute text values.
2020
function getTextAttrValue(node, attrName) {
2121
return getAttrTextValue(findAttr(node, attrName));
@@ -139,7 +139,21 @@ module.exports = {
139139
return;
140140
}
141141

142-
if (isNativeInteractive(node, getTextAttrValue)) {
142+
if (isHtmlInteractiveContent(node, getTextAttrValue)) {
143+
return;
144+
}
145+
146+
// Elements outside HTML §3.2.5.2.7 that are nonetheless ARIA widgets
147+
// or conventionally interactive surfaces — click-without-key on them
148+
// isn't what this rule targets. The HTML-content-model util covers
149+
// the spec-normative list; these are the ARIA-widget / convention
150+
// additions (see `html-interactive-content.js` docstring for why the
151+
// two authorities diverge).
152+
// - <canvas>: drawing/game surface (axobject-query: CanvasRole).
153+
// - <option>: ARIA role="option" (widget).
154+
// - <datalist>: ARIA role="listbox" (widget).
155+
const lowerTag = node.tag.toLowerCase();
156+
if (lowerTag === 'canvas' || lowerTag === 'option' || lowerTag === 'datalist') {
143157
return;
144158
}
145159

lib/utils/html-interactive-content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function isHtmlInteractiveContent(node, getTextAttrValue, options = {}) {
6363
// input — interactive unless type="hidden"
6464
if (tag === 'input') {
6565
const type = getTextAttrValue(node, 'type');
66-
return type === undefined || type === null || type.trim().toLowerCase() !== 'hidden';
66+
return type !== 'hidden';
6767
}
6868

6969
// a — interactive only when href is present

lib/utils/native-interactive-elements.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/lib/utils/html-interactive-content-test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ describe('isHtmlInteractiveContent', () => {
5353
isHtmlInteractiveContent(makeNode('input', { type: 'hidden' }), getTextAttrValue)
5454
).toBe(false);
5555
});
56-
57-
it('is NOT interactive when type="HIDDEN" (case-insensitive)', () => {
58-
expect(
59-
isHtmlInteractiveContent(makeNode('input', { type: 'HIDDEN' }), getTextAttrValue)
60-
).toBe(false);
61-
});
62-
63-
it('is NOT interactive when type=" hidden " (whitespace-trimmed)', () => {
64-
expect(
65-
isHtmlInteractiveContent(makeNode('input', { type: ' hidden ' }), getTextAttrValue)
66-
).toBe(false);
67-
});
6856
});
6957

7058
describe('<a>', () => {

tests/lib/utils/native-interactive-elements-test.js

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)