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

fix: useId instead of random number for tooltip ID #3094

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mcmcgrath13
Copy link

Summary

Related Issues or PRs

Alternate approach to #2562, which does not change the API of the Tooltip component. Use React's useId to generate a unique identifier instead of a random number.

This is the expected way to generate IDs, so plays nicely with server side rendering frameworks and is easy to mock for unit or snapshot tests.

Example of jest config for mocking

// Make sure the auto-generated IDs are stable for snapshot testing
jest.mock("react", () => ({
  ...jest.requireActual("react"),
  useId: () => "r:id",
}));

How To Test

This is a pure bugfix/refactor. It makes no change to API or UI

@mcmcgrath13 mcmcgrath13 marked this pull request as ready for review February 24, 2025 14:09
@mcmcgrath13 mcmcgrath13 requested a review from a team as a code owner February 24, 2025 14:09
@mcmcgrath13
Copy link
Author

@crwallace the README says you are an active maintainer - would you be able to approve running the workflow for the tests?

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.

1 participant