sparkdesignsystem / spark-design-system

Spark Design System
https://sparkdesignsystem.com
MIT License
107 stars 74 forks source link

Cannot use uniqueID on defaultProps (React: SprkToggle, SprkMastheadAccordionItem) #3472

Closed RVMendoza closed 4 years ago

RVMendoza commented 4 years ago

Describe The Bug

If you were to put two Toggles on the same page, they would not have unique Ids, even though they are being set on defaultProps (which is the problem).

We cannot use uniqueID() on defaultProps because defaultProps is a static property, which means it doesn't change on every new class.

This makes sense because if the value is different on every instance of the class, it wouldn't be considered default, and in your case, it shouldn't be.

Source: https://stackoverflow.com/questions/57628582/reactjs-difference-between-generates-a-unique-id-via-default-props-and-state

React Components Affected:

To Reproduce

Steps to reproduce the behavior:

  1. Go to SprkToggle story
  2. Copy Toggle and make it show twice
  3. Build, and observe that the ids and corresponding accessibility attributes are all the same

Expected Behavior

If multiple components exist on the same page, their ID and accessibility attribute pairing should be unique to each instance.

Kalovelo commented 4 years ago

Hello @RVMendoza , could I solve this issue for hacktoberfest2020? Thank you!

RVMendoza commented 4 years ago

@Kalovelo go for it!

RVMendoza commented 4 years ago

Thank you for your help with this @Kalovelo !

This will be on the next release! tenor-49649675

Kalovelo commented 4 years ago

Thank you for your help with this @Kalovelo !

This will be on the next release! tenor-49649675

Thank you for the opportunity ♥️