Skip to content

Commit

Permalink
Merge pull request #231 from p2kmgcl/issue/209
Browse files Browse the repository at this point in the history
Issue/209
  • Loading branch information
Robert Frampton authored Aug 24, 2017
2 parents 4604747 + 208a599 commit 8176b78
Show file tree
Hide file tree
Showing 2 changed files with 14 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
10 changes: 10 additions & 0 deletions packages/metal-dom/test/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ describe('dom', function() {
dom.toggleClasses(element, 'adipiscing elit lorem sit consectetur');
assert.strictEqual('ipsum dolor amet adipiscing elit consectetur', element.className);
});

it('should return false when checking if a classname with spaces exists', function() {
let el = document.createElement('div');
dom.addClasses(el, 'foo');
dom.addClasses(el, 'bar');
assert.strictEqual(dom.hasClass(el, 'foo'), true);
assert.strictEqual(dom.hasClass(el, 'bar'), true);
assert.strictEqual(dom.hasClass(el, 'foo bar'), false);
assert.strictEqual(dom.hasClass(el, 'bar foo'), false);
});
});

describe('contains', function() {
Expand Down

0 comments on commit 8176b78

Please sign in to comment.