Skip to content

Commit

Permalink
Check if addClass is truthy before adding it to element
Browse files Browse the repository at this point in the history
DOMTokenList::add() throws a DOMException if you try to add an empty string as a class. This check prevents this from happening so that you can set ValidationInputValidCssClassName etc. to an empty string if you don't want to add classes for valid input fields or messages for instance.
  • Loading branch information
davidkarlsson committed Nov 2, 2023
1 parent 4956e54 commit 2525091
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ export class ValidationService {
* @param removeClass Class to remove
*/
private swapClasses(element: Element, addClass: string, removeClass: string) {
if (!element.classList.contains(addClass)) {
if (addClass && !element.classList.contains(addClass)) {
element.classList.add(addClass);
}
if (element.classList.contains(removeClass)) {
Expand Down

0 comments on commit 2525091

Please sign in to comment.