Skip to content

Your app looks AI-generated. Vincent Van Gogh noticed. An agent skill that finds and fixes AI-looking UI and UX in mobile apps, web apps, and websites.

fix(detect): ignore data-role and data-tabindex in clickable-div (#333)

Pranav Arya105597a2cf8a
diff --git a/skills/unslop-anything/scripts/detect.js b/skills/unslop-anything/scripts/detect.js
index 1ee0d96..019f47b 100644
--- a/skills/unslop-anything/scripts/detect.js
+++ b/skills/unslop-anything/scripts/detect.js
@@ -1426,9 +1426,10 @@ const rules = [
// A non-semantic clickable element (or href-less anchor) is only
// keyboard- and screen-reader-accessible when it has both an
// interactive ARIA role and a tabIndex.
+ // `data-role` and `data-tabindex` are neither, so a hyphen before the name does not count (#323).
if (
- /\brole\s*=\s*["'{`]*\s*(?:button|link|checkbox|menuitem(?:checkbox|radio)?|option|radio|switch|tab|textbox|combobox|gridcell|searchbox|slider|spinbutton|treeitem)\b/.test(tag) &&
- /\btab[iI]ndex\s*=/.test(tag)
+ /(?<![\w-])role\s*=\s*["'{`]*\s*(?:button|link|checkbox|menuitem(?:checkbox|radio)?|option|radio|switch|tab|textbox|combobox|gridcell|searchbox|slider|spinbutton|treeitem)\b/.test(tag) &&
+ /(?<![\w-])tab[iI]ndex\s*=/.test(tag)
) {
continue;
}
diff --git a/test/detect.test.js b/test/detect.test.js
index 107e8fd..6b7f32b 100644
--- a/test/detect.test.js
+++ b/test/detect.test.js
@@ -2925,6 +2925,39 @@ test("clickable-div flags click handlers on header, footer and figure (issue #28
assert.deepStrictEqual(linesFor("<figcaption onClick={open}>A</figcaption>\n"), []);
});
+test("clickable-div does not read data-role and data-tabindex as a role and a tab stop (issue #323)", () => {
+ const linesFor = (src, file = "Row.tsx") =>
+ scanSource(src, file)
+ .filter((f) => f.rule === "clickable-div")
+ .map((f) => f.line);
+
+ // Issue #323 repro:
+ const repro = [
+ "export const Row = ({ open }) => (",
+ ' <div data-role="button" data-tabindex="0" onClick={open}>Open</div>',
+ ");",
+ ].join("\n");
+ assert.deepStrictEqual(linesFor(repro), [2]);
+
+ // One real attribute next to a look-alike is still only one of the two
+ assert.deepStrictEqual(linesFor('<div role="button" data-tabindex="0" onClick={open}>Open</div>\n'), [1]);
+ assert.deepStrictEqual(linesFor('<div data-role="button" tabIndex={0} onClick={open}>Open</div>\n'), [1]);
+ // Other attributes that only end in role or tabindex
+ assert.deepStrictEqual(linesFor('<div data-user-role="button" tabIndex={0} onClick={open}>Open</div>\n'), [1]);
+ assert.deepStrictEqual(linesFor('<div role="button" data-row-tabindex="0" onClick={open}>Open</div>\n'), [1]);
+ assert.deepStrictEqual(linesFor('<div data-role="button" data-tabindex="0" onclick="open()">Open</div>\n', "row.html"), [1]);
+ assert.deepStrictEqual(linesFor('<div data-role="button" data-tabindex="0" @click="open">Open</div>\n', "Row.vue"), [1]);
+
+ // A real role with a real tabIndex stays quiet
+ assert.deepStrictEqual(linesFor('<div role="button" tabIndex={0} onClick={open}>Open</div>\n'), []);
+ assert.deepStrictEqual(linesFor('<div onClick={open} tabIndex={0} role="button">Open</div>\n'), []);
+ assert.deepStrictEqual(linesFor("<div\n role=\"button\"\n tabIndex={0}\n onClick={open}\n>Open</div>\n"), []);
+ assert.deepStrictEqual(linesFor('<div role="button" tabindex="0" onclick="open()">Open</div>\n', "row.html"), []);
+ assert.deepStrictEqual(linesFor('<div role="button" :tabindex="0" @click="open">Open</div>\n', "Row.vue"), []);
+ // Look-alikes next to the real pair do not undo it
+ assert.deepStrictEqual(linesFor('<div data-role="row" role="button" data-tabindex="1" tabIndex={0} onClick={open}>Open</div>\n'), []);
+});
+
test("template-theme flags create-vite's #646cff and #535bf2", () => {
const rulesFor = (src) => scanSource(src, "index.css").map((f) => f.rule).filter((r) => r === "template-theme");
assert.deepStrictEqual(rulesFor("a {\n font-weight: 500;\n color: #646cff;\n}\na:hover {\n color: #535bf2;\n}\n"), ["template-theme"]);