playcanvas / pcui

UI component library for web-based tools
http://playcanvas.github.io/pcui
MIT License
664 stars 62 forks source link

[BREAKING] Remove `Element#classAdd` and `Element#classRemove` #274

Closed willeastcott closed 1 year ago

willeastcott commented 1 year ago

This PR removes Element#classAdd and Element#classRemove from the API. Let's examine the docs for Element#classAdd:

Adds the specified class to the DOM element but checks if the classList contains it first.

It performs this check using the DOMTokenList#contains function.

Now let's examine the docs for DOMTokenList#add:

The add() method of the DOMTokenList interface adds the given tokens to the list, omitting any that are already present.

So Element#classAdd is entirely redundant because DOMTokenList#add already checks if a supplied class name is already present and does not add it twice.

The same applies to Element#classRemove.

Most of the PCUI codebase (plus apps built on PCUI) already do element.class.add/remove instead of element.classAdd/Remove. This PR migrates the remaining occurrences to simply use the DOMTokenList API.