10up / component-library

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

Generated tooltip IDs not unique #120

Closed johnwatkins0 closed 2 years ago

johnwatkins0 commented 2 years ago

PR incoming

Describe the bug

At this line: https://github.com/10up/component-library/blob/develop/packages/tooltips/src/tooltip.js#L52

Because those forEach callbacks run in parallel , this.count will always be 1 at https://github.com/10up/component-library/blob/develop/packages/tooltips/src/tooltip.js#L132

This results all the generated IDs and aria-describedby values on the page being tool_tip_1

To Reproduce Steps to reproduce the behavior:

  1. Create the markup for several tooltips on the page, all sharing the class .tooltip
  2. add new Tooltip('.tooltip'); in your JS
  3. See that all the generated IDs on the screen are the same

Expected behavior Each tooltip should have a unique ID.

Screenshots

Screen Shot 2022-09-20 at 9 24 19 AM