File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -1207,10 +1207,18 @@ export const ChartMixin = (superClass) =>
1207
1207
if ( ! self . tempBodyStyle ) {
1208
1208
let effectiveCss = '' ;
1209
1209
1210
+ // PolymerElement uses `<style>` tags for adding styles
1210
1211
[ ...self . shadowRoot . querySelectorAll ( 'style' ) ] . forEach ( ( style ) => {
1211
1212
effectiveCss += style . textContent ;
1212
1213
} ) ;
1213
1214
1215
+ // LitElement uses `adoptedStyleSheets` for adding styles
1216
+ if ( self . shadowRoot . adoptedStyleSheets ) {
1217
+ self . shadowRoot . adoptedStyleSheets . forEach ( ( sheet ) => {
1218
+ effectiveCss += [ ...sheet . cssRules ] . map ( ( rule ) => rule . cssText ) . join ( '\n' ) ;
1219
+ } ) ;
1220
+ }
1221
+
1214
1222
// Strip off host selectors that target individual instances
1215
1223
effectiveCss = effectiveCss . replace ( / : h o s t \( .+ ?\) / gu, ( match ) => {
1216
1224
const selector = match . substr ( 6 , match . length - 7 ) ;
Original file line number Diff line number Diff line change @@ -34,15 +34,17 @@ describe('vaadin-chart exporting', () => {
34
34
35
35
it ( 'should temporarily copy shadow styles to the body before export' , async ( ) => {
36
36
let styleCopiedToBody = false ;
37
+ let styleContent ;
37
38
38
39
// Track style movement into the document body
39
40
const observer = new MutationObserver ( ( mutations ) => {
40
- styleCopiedToBody ||= mutations . some (
41
- ( mutation ) =>
42
- Array . from ( mutation . addedNodes )
43
- . map ( ( node ) => node . tagName . toLowerCase ( ) )
44
- . indexOf ( 'style' ) >= 0 ,
45
- ) ;
41
+ mutations . forEach ( ( mutation ) => {
42
+ const styleTag = [ ...mutation . addedNodes ] . find ( ( node ) => node instanceof HTMLStyleElement ) ;
43
+ if ( styleTag ) {
44
+ styleCopiedToBody = true ;
45
+ styleContent = styleTag . textContent ;
46
+ }
47
+ } ) ;
46
48
} ) ;
47
49
48
50
observer . observe ( document . body , { childList : true } ) ;
@@ -57,6 +59,7 @@ describe('vaadin-chart exporting', () => {
57
59
expect ( fireEventSpy . firstCall . args [ 1 ] ) . to . be . equal ( 'beforeExport' ) ;
58
60
await nextRender ( chart ) ;
59
61
expect ( styleCopiedToBody ) . to . be . true ;
62
+ expect ( styleContent ) . to . include ( '.highcharts-color-0' ) ;
60
63
} ) ;
61
64
62
65
it ( 'should remove shadow styles from body after export' , async ( ) => {
You can’t perform that action at this time.
0 commit comments