Skip to content

Commit 2e8b626

Browse files
authored
fix: only use container queries fallback with font icons (#6401)
1 parent 2a68067 commit 2e8b626

2 files changed

Lines changed: 63 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,8 @@ class Icon extends ThemableMixin(
254254
this._tooltipController = new TooltipController(this);
255255
this.addController(this._tooltipController);
256256

257-
if (needsFontIconSizingFallback) {
258-
// Call once initially to avoid a fouc
259-
this._onResize();
260-
}
257+
// Call once initially to avoid a fouc
258+
this._onResize();
261259
}
262260

263261
/** @protected */
@@ -370,10 +368,13 @@ class Icon extends ThemableMixin(
370368
this.classList.add(...this.__addedFontClasses);
371369
}
372370

373-
// The "icon" attribute needs to be set on the host also when using font icons
374-
// to avoid issues such as https://github.com/vaadin/web-components/issues/6301
375-
if ((font || char) && !this.icon) {
376-
this.icon = '';
371+
if (font || char) {
372+
if (!this.icon) {
373+
// The "icon" attribute needs to be set on the host also when using font icons
374+
// to avoid issues such as https://github.com/vaadin/web-components/issues/6301
375+
this.icon = '';
376+
}
377+
this._onResize();
377378
}
378379
}
379380

@@ -387,7 +388,9 @@ class Icon extends ThemableMixin(
387388
* @override
388389
*/
389390
_onResize() {
390-
this.style.setProperty('--_vaadin-font-icon-size', `${this.offsetHeight}px`);
391+
if (needsFontIconSizingFallback && (this.char || this.font)) {
392+
this.style.setProperty('--_vaadin-font-icon-size', `${this.offsetHeight}px`);
393+
}
391394
}
392395
}
393396

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

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@esm-bundle/chai';
2-
import { fixtureSync } from '@vaadin/testing-helpers';
2+
import { fixtureSync, nextFrame } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import '../vaadin-icon.js';
55
import { isSafari } from '@vaadin/component-base/src/browser-utils.js';
@@ -169,4 +169,54 @@ describe('vaadin-icon - icon fonts', () => {
169169
expect(['"My icons"', 'My icons']).to.include(fontIconStyle.fontFamily);
170170
});
171171
});
172+
173+
// These tests make sure that the heavy container query fallback is only used
174+
// when font icons are used.
175+
(usesFontIconSizingFallback ? describe : describe.skip)('container query fallback', () => {
176+
let icon;
177+
178+
it('should have the custom property (font)', async () => {
179+
icon = fixtureSync('<vaadin-icon font="foo"></vaadin-icon>');
180+
await nextFrame();
181+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px');
182+
});
183+
184+
it('should have the custom property (char)', async () => {
185+
icon = fixtureSync('<vaadin-icon char="foo"></vaadin-icon>');
186+
await nextFrame();
187+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px');
188+
});
189+
190+
it('should not have the custom property', async () => {
191+
icon = fixtureSync('<vaadin-icon></vaadin-icon>');
192+
await nextFrame();
193+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('');
194+
});
195+
196+
it('should set the custom property', async () => {
197+
icon = fixtureSync('<vaadin-icon></vaadin-icon>');
198+
await nextFrame();
199+
icon.font = 'foo';
200+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('24px');
201+
});
202+
203+
it('should update the custom property', async () => {
204+
icon = fixtureSync('<vaadin-icon font="foo"></vaadin-icon>');
205+
await nextFrame();
206+
icon.style.width = '100px';
207+
icon.style.height = '100px';
208+
await onceResized(icon);
209+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('100px');
210+
});
211+
212+
it('should not update the custom property', async () => {
213+
icon = fixtureSync('<vaadin-icon></vaadin-icon>');
214+
await nextFrame();
215+
icon.style.width = '100px';
216+
icon.style.height = '100px';
217+
await nextFrame(icon);
218+
await nextFrame(icon);
219+
expect(icon.style.getPropertyValue('--_vaadin-font-icon-size')).to.equal('');
220+
});
221+
});
172222
});

0 commit comments

Comments
 (0)