10up / component-library

A library of barebones front-end components built with WordPress and accessibility in mind.
https://baseline.10up.com/
MIT License
58 stars 11 forks source link

Use forEach index to generate unique ID #121

Closed johnwatkins0 closed 1 year ago

johnwatkins0 commented 1 year ago

Description of the Change

Fixes #120 by using the forEach index instead of this.count to generate a unique ID for tooltips.

Alternate Designs

Incrementing this.count in place like below also worked in local testing, but I think the forEach index is more reliable.

tip.setAttribute('id', `tool_tip_${this.count++}`);

Benefits

Possible Drawbacks

This is a quick fix for my current project, but there will still be duplicate tooltip IDs on the page if the Tooltip class is instantiated multiple times on the page with different selectors.

The unique IDs should be generated using the uuid package, or the Tooltip class should allow passing in an ID prefix. Or the number of Tooltip instances could be tracked in the global scope.

Verification Process

Checklist:

Applicable Issues

120

cypress[bot] commented 1 year ago



Test summary

11 0 1 0


Run details

Project @10up/component-library
Status Passed
Commit 8c347f9dec ℹ️
Started Sep 20, 2022 2:38 PM
Ended Sep 20, 2022 2:39 PM
Duration 00:43 💡
OS Linux Ubuntu - 20.04
Browser Chrome 105

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard