Skip to content

Commit ccbddfe

Browse files
Kk25380tdesign-bot
andauthored
fix(icon): apply font-size on first render for non-image icons (#4711)
* fix(icon): apply font-size on first render for non-image icons Apply iconStyle (including font-size) on the first setData for non-image icons so the initial frame uses the requested size. The image branch keeps its getRect-based width/height calculation unchanged. * test(calendar): update snapshot for first-render icon font-size The icon fix writes iconStyle on the first setData, so the close icon in calendar now renders with font-size: 48rpx on the first frame instead of an empty style. Update the :base snapshot accordingly. Relates to #4706. * chore: stash changelog [ci skip] * refactor(icon): remove redundant isImage guard after early return --------- Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent 5c70aeb commit ccbddfe

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎packages/components/calendar/__test__/__snapshots__/index.test.js.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ exports[`calendar :base 1`] = `
5454
ariaLabel="关闭"
5555
ariaRole="button"
5656
class="t-icon class t-class"
57-
style=""
57+
style="font-size: 48rpx;"
5858
bind:tap="onTap"
5959
>
6060
<wx-label

‎packages/components/icon/icon.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,23 @@ export default class Icon extends SuperComponent {
3939
const fontStyle = size ? { 'font-size': sizeValue } : {};
4040
const iconStyle: Record<string, any> = { ...colorStyle, ...fontStyle };
4141

42+
if (!isImage) {
43+
this.setData({ isImage, iconStyle: `${styles(iconStyle)}` });
44+
return;
45+
}
46+
4247
this.setData({ isImage }, async () => {
43-
if (isImage) {
44-
let iconSize = sizeValue;
45-
if (!iconSize) {
46-
await getRect(this, `.${classPrefix}`)
47-
.then((res) => {
48-
iconSize = addUnit(res?.height);
49-
})
50-
.catch(() => {});
51-
}
52-
53-
iconStyle.width = iconSize;
54-
iconStyle.height = iconSize;
48+
let iconSize = sizeValue;
49+
if (!iconSize) {
50+
await getRect(this, `.${classPrefix}`)
51+
.then((res) => {
52+
iconSize = addUnit(res?.height);
53+
})
54+
.catch(() => {});
5555
}
56+
57+
iconStyle.width = iconSize;
58+
iconStyle.height = iconSize;
5659
this.setData({ iconStyle: `${styles(iconStyle)}` });
5760
});
5861
},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4711
3+
contributor: Kk25380
4+
---
5+
6+
- fix(icon): 修复指定 size 后首次渲染字号跳变 @Kk25380 ([#4711](https://github.com/Tencent/tdesign-miniprogram/pull/4711))

0 commit comments

Comments
 (0)