Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Commit

Permalink
Merge pull request #326 from webcomponents/wrap-className
Browse files Browse the repository at this point in the history
Put `className` on the element wrapper
  • Loading branch information
dfreedm authored Apr 2, 2019
2 parents 95f75cf + 28709da commit fdc2643
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ class Wrapper {
this.node[utils.SHADY_PREFIX + 'slot'] = value;
}

get className() {
return this.node[utils.SHADY_PREFIX + 'className'];
}

set className(value) {
return this.node[utils.SHADY_PREFIX + 'className'] = value;
}

}

eventPropertyNames.forEach(name => {
Expand Down
16 changes: 16 additions & 0 deletions tests/sync-style-scoping.html
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,22 @@
});
});

suite('mutation', function() {
test('setting class and className works and preserves scoping', function() {
const el = document.createElement('api-element');
ShadyDOM.wrap(arena).appendChild(el);
const inner = ShadyDOM.wrap(ShadyDOM.wrap(el).shadowRoot).querySelector('#internal');
const innerWrapper = ShadyDOM.wrap(inner);
assert.equal(csfn(inner), 'api-element');
innerWrapper.setAttribute('class', 'a');
assert.isTrue(inner.classList.contains('a'));
assert.equal(csfn(inner), 'api-element');
innerWrapper.className = 'b';
assert.isTrue(inner.classList.contains('b'));
assert.equal(csfn(inner), 'api-element');
})
});

suite('elements not owned by the main document', function() {
let el;
const template = document.createElement('template');
Expand Down

0 comments on commit fdc2643

Please sign in to comment.