diff --git a/packages/icon/src/vaadin-icon-helpers.js b/packages/icon/src/vaadin-icon-helpers.js index 0d5b63157c2..7d9a7a59e5f 100644 --- a/packages/icon/src/vaadin-icon-helpers.js +++ b/packages/icon/src/vaadin-icon-helpers.js @@ -28,11 +28,21 @@ export function supportsCQUnitsForPseudoElements() { const testElement = document.createElement('div'); testElement.classList.add('vaadin-icon-test-element'); - document.body.append(testStyle, testElement); - const { height } = getComputedStyle(testElement, '::before'); + const shadowParent = document.createElement('div'); + shadowParent.attachShadow({ mode: 'open' }); + shadowParent.shadowRoot.innerHTML = ''; + shadowParent.append(testElement.cloneNode()); + + document.body.append(testStyle, testElement, shadowParent); + + const needsFallback = [...document.querySelectorAll('.vaadin-icon-test-element')].find( + (el) => getComputedStyle(el, '::before').height !== '2px', + ); + testStyle.remove(); testElement.remove(); - return height === '2px'; + shadowParent.remove(); + return !needsFallback; } /** diff --git a/packages/icon/test/icon-font.test.js b/packages/icon/test/icon-font.test.js index f0059d94f7f..094693b6e08 100644 --- a/packages/icon/test/icon-font.test.js +++ b/packages/icon/test/icon-font.test.js @@ -334,5 +334,18 @@ describe('vaadin-icon - icon fonts', () => { await nextFrame(icon); expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal(''); }); + + fallBackIt('should have the same height as the host with shadow root', async () => { + icon = fixtureSync(''); + const parent = fixtureSync('
'); + parent.attachShadow({ mode: 'open' }); + parent.shadowRoot.innerHTML = ''; + + parent.append(icon); + await nextResize(icon); + + const fontIconStyle = getComputedStyle(icon, ':before'); + expect(parseInt(fontIconStyle.height)).to.be.closeTo(24, 1); + }); }); });