Skip to content

Commit dbeb07f

Browse files
committed
Adds toString to CSSResult
1 parent 0093b43 commit dbeb07f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/lib/css-tag.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export class CSSResult {
4242
}
4343
return this._styleSheet;
4444
}
45+
46+
toString(): String {
47+
return this.cssText;
48+
}
4549
}
4650

4751
/**

src/test/lit-element_styling_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ suite('Static get styles', () => {
768768
const div = el.shadowRoot!.querySelector('div');
769769
assert.equal(getComputedStyle(div!).getPropertyValue('border-top-width').trim(), '4px');
770770
});
771+
772+
test('`CSSResult` allows for String type coercion via toString()', async () => {
773+
const cssModule = css`.my-module { color: yellow; }`;
774+
// Coercion allows for reusage of css-tag outcomes in regular strings.
775+
// Example use case: apply cssModule as global page styles at document.body level.
776+
const bodyStyles = `${cssModule}`;
777+
assert.equal(bodyStyles, '.my-module { color: yellow; }');
778+
});
771779
});
772780

773781
suite('ShadyDOM', () => {

0 commit comments

Comments
 (0)