Skip to content

fix: Link to should be allowed to have tooltip #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-ravens-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-primer-react": patch
---

fix: Link to should be allowed to have tooltip
16 changes: 16 additions & 0 deletions src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ ruleTester.run('non-interactive-tooltip-trigger', rule, {
</Link>
</Tooltip>
`,
`
import {Tooltip, Link} from '@primer/react';
<Tooltip aria-label="product" direction="e">
<Link to={productLink}>
Product
</Link>
</Tooltip>
`,
`
import {Tooltip, Link} from '@primer/react';
<Tooltip aria-label="product" direction="e">
<Link to="https://github.com">
Product
</Link>
</Tooltip>
`,
],
invalid: [
{
Expand Down
12 changes: 9 additions & 3 deletions src/rules/a11y-tooltip-interactive-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ 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
}

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

Expand Down