Skip to content

Commit 63ef9fd

Browse files
authored
fix: Link to should be allowed to have tooltip (#314)
* fix: Link to should be allowed to have tooltip * Fix lint * fix tests * Create soft-ravens-share.md
1 parent cd59627 commit 63ef9fd

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.changeset/soft-ravens-share.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-primer-react": patch
3+
---
4+
5+
fix: Link to should be allowed to have tooltip

src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ ruleTester.run('non-interactive-tooltip-trigger', rule, {
6767
</Link>
6868
</Tooltip>
6969
`,
70+
`
71+
import {Tooltip, Link} from '@primer/react';
72+
<Tooltip aria-label="product" direction="e">
73+
<Link to={productLink}>
74+
Product
75+
</Link>
76+
</Tooltip>
77+
`,
78+
`
79+
import {Tooltip, Link} from '@primer/react';
80+
<Tooltip aria-label="product" direction="e">
81+
<Link to="https://github.com">
82+
Product
83+
</Link>
84+
</Tooltip>
85+
`,
7086
],
7187
invalid: [
7288
{

src/rules/a11y-tooltip-interactive-trigger.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@ const isAnchorTag = el => {
2323
}
2424

2525
const isJSXValue = attributes => {
26-
const node = attributes.find(attribute => propName(attribute) === 'href')
26+
const node = attributes.find(attribute => propName(attribute) === 'href' || propName(attribute))
2727
const isJSXExpression = node.value.type === 'JSXExpressionContainer' && node && typeof getPropValue(node) === 'string'
2828

2929
return isJSXExpression
3030
}
3131

3232
const isInteractiveAnchor = child => {
3333
const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href')
34-
if (!hasHref) return false
35-
const href = getJSXOpeningElementAttribute(child.openingElement, 'href').value.value
34+
const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to')
35+
36+
if (!hasHref && !hasTo) return false
37+
38+
const href = hasHref
39+
? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value
40+
: getJSXOpeningElementAttribute(child.openingElement, 'to').value.value
41+
3642
const hasJSXValue = isJSXValue(child.openingElement.attributes)
3743
const isAnchorInteractive = (typeof href === 'string' && href !== '') || hasJSXValue
3844

0 commit comments

Comments
 (0)