Skip to content
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

Add an eslint rule for checking interactivity of tooltip trigger #51

Merged
merged 7 commits into from
May 26, 2023

Conversation

broccolinisoup
Copy link
Member

@broccolinisoup broccolinisoup commented May 18, 2023

Adding an eslint rule to check if the Tooltip component includes an interactive trigger.

Rule Details

This rule enforces to use interactive elements as tooltip triggers. Interactive elements can be Primer Button, IconButton and Link components or native elements like button, a with an href attribute, select, textarea, summary and input (that is not a hidden type).

👎 Examples of incorrect code for this rule:

/* eslint primer-react/a11y-tooltip-non-interactive-trigger: "error" */
import {Tooltip} from '@primer/react'
const App = () => (
  <Tooltip text="Tooltip text">
    <div>Tooltip trigger</div>
  </Tooltip>
)

👍 Examples of correct code for this rule:

/* eslint primer-react/a11y-tooltip-non-interactive-trigger: "error" */
import {Tooltip, Button} from '@primer/react'
const App = () => (
  <Tooltip text="Supplementary text" type="description">
    <Button
      onClick={() => {
        /* do something */
      }}
    >
      Save
    </Button>
  </Tooltip>
)

Options

  • skipImportCheck (default: false)

    By default, the a11y-tooltip-non-interactive-trigger rule will only check for interactive elements in components that are imported from @primer/react. You can disable this behavior by setting skipImportCheck to true. This is used for internal linting in the primer/react repository.

@changeset-bot
Copy link

changeset-bot bot commented May 18, 2023

🦋 Changeset detected

Latest commit: 33b5969

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-primer-react Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@broccolinisoup broccolinisoup marked this pull request as ready for review May 18, 2023 13:41
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So cool! 🥳 Loving this plugin. Left a couple of comments and questions, let me know what you think 👀

src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
src/rules/non-interactive-tooltip-trigger.js Outdated Show resolved Hide resolved
broccolinisoup and others added 2 commits May 19, 2023 19:27
Co-authored-by: Josh Black <joshblack@github.com>
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good! 🔥

@broccolinisoup
Copy link
Member Author

@joshblack I realised that I forgot to add some Primer components 🙈 Like Link and TextInput, so I added them along with docs. I also renamed the file to have prefix a11y-tooltip for accessibility team to use filter the disabled eslint rules for accessibility score cards. All in this commit Let me know if you have any feedback! Thanks so much again for the review 🙏🏻

@colebemis
Copy link
Contributor

colebemis commented May 22, 2023

Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, @broccolinisoup! Just left one naming suggestion.

src/configs/recommended.js Outdated Show resolved Hide resolved
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, @broccolinisoup! Just left one naming suggestion.

@broccolinisoup broccolinisoup merged commit 98ff0b2 into main May 26, 2023
@primer-css primer-css mentioned this pull request May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants