From e5c9281ccacf119ae88f069ca4c0eb7f3b57c0db Mon Sep 17 00:00:00 2001
From: Kate Higa <16447748+khiga8@users.noreply.github.com>
Date: Wed, 12 Feb 2025 12:05:57 -0500
Subject: [PATCH 1/4] fix: Link to should be allowed to have tooltip
---
.../a11y-tooltip-interactive-trigger.test.js | 16 ++++++++++++++++
src/rules/a11y-tooltip-interactive-trigger.js | 7 +++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js b/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js
index a5e0e1dc..4c289376 100644
--- a/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js
+++ b/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js
@@ -67,6 +67,22 @@ ruleTester.run('non-interactive-tooltip-trigger', rule, {
`,
+ `
+ import {Tooltip, Link} from '@primer/react';
+
+
+ Product
+
+
+ `,
+ `
+ import {Tooltip, Link} from '@primer/react';
+
+
+ Product
+
+
+ `,
],
invalid: [
{
diff --git a/src/rules/a11y-tooltip-interactive-trigger.js b/src/rules/a11y-tooltip-interactive-trigger.js
index f252cd91..c0c7475d 100644
--- a/src/rules/a11y-tooltip-interactive-trigger.js
+++ b/src/rules/a11y-tooltip-interactive-trigger.js
@@ -31,8 +31,11 @@ const isJSXValue = attributes => {
const isInteractiveAnchor = child => {
const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href')
- if (!hasHref) return false
- const href = getJSXOpeningElementAttribute(child.openingElement, 'href').value.value
+ const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to')
+ if (!hasHref && !hasTo) return false
+
+ const href = hasHref ? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value : getJSXOpeningElementAttribute(child.openingElement, 'to').value.value
+
const hasJSXValue = isJSXValue(child.openingElement.attributes)
const isAnchorInteractive = (typeof href === 'string' && href !== '') || hasJSXValue
From b685bf2df4b9d6931359a5ba4f573c6e1e44fd6d Mon Sep 17 00:00:00 2001
From: Kate Higa <16447748+khiga8@users.noreply.github.com>
Date: Wed, 12 Feb 2025 12:13:00 -0500
Subject: [PATCH 2/4] Fix lint
---
src/rules/a11y-tooltip-interactive-trigger.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/rules/a11y-tooltip-interactive-trigger.js b/src/rules/a11y-tooltip-interactive-trigger.js
index c0c7475d..556c2b46 100644
--- a/src/rules/a11y-tooltip-interactive-trigger.js
+++ b/src/rules/a11y-tooltip-interactive-trigger.js
@@ -33,8 +33,10 @@ const isInteractiveAnchor = child => {
const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href')
const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to')
if (!hasHref && !hasTo) return false
-
- const href = hasHref ? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value : getJSXOpeningElementAttribute(child.openingElement, 'to').value.value
+
+ const href = hasHref
+ ? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value
+ : getJSXOpeningElementAttribute(child.openingElement, 'to').value.value
const hasJSXValue = isJSXValue(child.openingElement.attributes)
const isAnchorInteractive = (typeof href === 'string' && href !== '') || hasJSXValue
From df91e84716851c306f22829180a78c5221ef6a2c Mon Sep 17 00:00:00 2001
From: Kate Higa <16447748+khiga8@users.noreply.github.com>
Date: Wed, 12 Feb 2025 12:30:41 -0500
Subject: [PATCH 3/4] fix tests
---
src/rules/a11y-tooltip-interactive-trigger.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/rules/a11y-tooltip-interactive-trigger.js b/src/rules/a11y-tooltip-interactive-trigger.js
index 556c2b46..5ed70dc7 100644
--- a/src/rules/a11y-tooltip-interactive-trigger.js
+++ b/src/rules/a11y-tooltip-interactive-trigger.js
@@ -23,7 +23,7 @@ const isAnchorTag = el => {
}
const isJSXValue = attributes => {
- const node = attributes.find(attribute => propName(attribute) === 'href')
+ const node = attributes.find(attribute => propName(attribute) === 'href' || propName(attribute))
const isJSXExpression = node.value.type === 'JSXExpressionContainer' && node && typeof getPropValue(node) === 'string'
return isJSXExpression
@@ -32,6 +32,7 @@ const isJSXValue = attributes => {
const isInteractiveAnchor = child => {
const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href')
const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to')
+
if (!hasHref && !hasTo) return false
const href = hasHref
From e41d7c5bc066a70a1d80ff575a64812241b626a8 Mon Sep 17 00:00:00 2001
From: Kate Higa <16447748+khiga8@users.noreply.github.com>
Date: Wed, 12 Feb 2025 12:31:00 -0500
Subject: [PATCH 4/4] Create soft-ravens-share.md
---
.changeset/soft-ravens-share.md | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 .changeset/soft-ravens-share.md
diff --git a/.changeset/soft-ravens-share.md b/.changeset/soft-ravens-share.md
new file mode 100644
index 00000000..a7e389e3
--- /dev/null
+++ b/.changeset/soft-ravens-share.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-primer-react": patch
+---
+
+fix: Link to should be allowed to have tooltip