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

Update tabs.js #119

Open aaronware opened 2 years ago

aaronware commented 2 years ago

Description of the Change

This is a minor change to handle targeting the click event in the case where you have nested elements within your tab links.

Example of the HTML markup that this impacts: Notice the nested span within the tab link markup

<a role="tab" id="tab-products" aria-controls="products" class="products-search-tab" aria-selected="true">
                            Products <span class="count">(13)</span>
                        </a>

When utilizing .addEventListener with a click event:

This is very important in this case because when you click on the span, the tab target content will actually be null by utilizing event.currentTarget instead, you then negate any child elements of the tab click event

Alternate Designs

I did not research any other alternatives as this is pretty standard

Benefits

Backward compatible with the current implementation and allows for a more complex HTML structure without breaking tab functionality

Possible Drawbacks

None that I came across

Verification Process

Checklist: