Skip to content

Commit

Permalink
Updated hasClassWithNative_ and hasClassWithoutNative_
Browse files Browse the repository at this point in the history
Now the pass the given test. For the case of hasClassWithNative_, it
tries to use the native methods, but catches a dom exception with
the text "contains HTML space characters", other exceptions are thrown.
  • Loading branch information
Pablo Molina authored and Pablo Molina committed Aug 24, 2017
1 parent 9cf0a97 commit 208a599
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/metal-dom/src/domNamed.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ export function hasClass(element, className) {
* @private
*/
function hasClassWithNative_(element, className) {
return element.classList.contains(className);
return className.indexOf(' ') === -1 &&
element.classList.contains(className);
}

/**
Expand All @@ -351,7 +352,8 @@ function hasClassWithNative_(element, className) {
* @private
*/
function hasClassWithoutNative_(element, className) {
return (` ${element.className} `).indexOf(` ${className} `) >= 0;
return (` ${element.className} `).indexOf(` ${className} `) >= 0 &&
className.split(' ').length === 1;
}

/**
Expand Down

0 comments on commit 208a599

Please sign in to comment.