Skip to content

Commit 76aedca

Browse files
authored
fix: check for CQU in shadow container for Safari (#10296) (#10325)
1 parent c183715 commit 76aedca

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/icon/src/vaadin-icon-helpers.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,21 @@ export function supportsCQUnitsForPseudoElements() {
2828
const testElement = document.createElement('div');
2929
testElement.classList.add('vaadin-icon-test-element');
3030

31-
document.body.append(testStyle, testElement);
32-
const { height } = getComputedStyle(testElement, '::before');
31+
const shadowParent = document.createElement('div');
32+
shadowParent.attachShadow({ mode: 'open' });
33+
shadowParent.shadowRoot.innerHTML = '<slot></slot>';
34+
shadowParent.append(testElement.cloneNode());
35+
36+
document.body.append(testStyle, testElement, shadowParent);
37+
38+
const needsFallback = [...document.querySelectorAll('.vaadin-icon-test-element')].find(
39+
(el) => getComputedStyle(el, '::before').height !== '2px',
40+
);
41+
3342
testStyle.remove();
3443
testElement.remove();
35-
return height === '2px';
44+
shadowParent.remove();
45+
return !needsFallback;
3646
}
3747

3848
/**

packages/icon/test/icon-font.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,18 @@ describe('vaadin-icon - icon fonts', () => {
334334
await nextFrame(icon);
335335
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('');
336336
});
337+
338+
fallBackIt('should have the same height as the host with shadow root', async () => {
339+
icon = fixtureSync('<vaadin-icon char="foo" style="--vaadin-icon-size: 24px"></vaadin-icon>');
340+
const parent = fixtureSync('<div></div>');
341+
parent.attachShadow({ mode: 'open' });
342+
parent.shadowRoot.innerHTML = '<slot></slot>';
343+
344+
parent.append(icon);
345+
await nextResize(icon);
346+
347+
const fontIconStyle = getComputedStyle(icon, ':before');
348+
expect(parseInt(fontIconStyle.height)).to.be.closeTo(24, 1);
349+
});
337350
});
338351
});

0 commit comments

Comments
 (0)