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

Put className on the element wrapper #326

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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