Skip to content

Commit 641cac2

Browse files
tbroyercalebdwilliams
authored andcommitted
feat: reflect custom states as shadow parts in addition to attributes
Fixes #62
1 parent e30a41b commit 641cac2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Diff for: src/CustomStateSet.ts

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export class CustomStateSet extends Set<string> {
2020
const result = super.add(state);
2121
const ref = customStateMap.get(this);
2222
ref.toggleAttribute(`state${state}`, true);
23+
if (ref.part) {
24+
ref.part.add(`state--${state}`);
25+
}
2326
return result;
2427
}
2528

@@ -34,6 +37,9 @@ export class CustomStateSet extends Set<string> {
3437
const result = super.delete(state);
3538
const ref = customStateMap.get(this);
3639
ref.toggleAttribute(`state${state}`, false);
40+
if (ref.part) {
41+
ref.part.remove(`state--${state}`);
42+
}
3743
return result;
3844
}
3945
}

Diff for: test/CustomStateSet.test.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,45 @@ describe('CustomStateSet polyfill', () => {
1515
fixtureCleanup();
1616
});
1717

18-
describe('it will add attributes', async () => {
18+
describe('it will add attributes and parts', async () => {
1919
set.add('--foo');
2020
expect(el.hasAttribute('state--foo')).to.be.true;
21+
if (el.part) {
22+
expect(el.part.contains('state--foo')).to.be.true;
23+
}
2124
});
2225

23-
describe('it will remove attributes', async () => {
26+
describe('it will remove attributes and parts', async () => {
2427
set.add('--foo');
2528
expect(el.hasAttribute('state--foo')).to.be.true;
29+
if (el.part) {
30+
expect(el.part.contains('state--foo')).to.be.true;
31+
}
2632

2733
set.delete('--foo');
2834
expect(el.hasAttribute('state--foo')).to.be.false;
35+
if (el.part) {
36+
expect(el.part.contains('state--foo')).to.be.false;
37+
}
2938
});
3039

31-
describe('it will clear all attributes', async () => {
40+
describe('it will clear all attributes and parts', async () => {
3241
set.add('--foo');
3342
set.add('--bar');
3443

3544
expect(el.hasAttribute('state--foo')).to.be.true;
3645
expect(el.hasAttribute('state--bar')).to.be.true;
46+
if (el.part) {
47+
expect(el.part.contains('state--foo')).to.be.true;
48+
expect(el.part.contains('state--bar')).to.be.true;
49+
}
3750

3851
set.clear();
3952
expect(el.hasAttribute('state--foo')).to.be.false;
4053
expect(el.hasAttribute('state--bar')).to.be.false;
54+
if (el.part) {
55+
expect(el.part.contains('state--foo')).to.be.false;
56+
expect(el.part.contains('state--bar')).to.be.false;
57+
}
4158
});
4259
});

0 commit comments

Comments
 (0)