diff --git a/src/common/utils.ts b/src/common/utils.ts index 1aee6c9fc..d59855ade 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -200,14 +200,14 @@ export const getInstance = function (context?: Context, selector?: string) { return instance; }; -export const unitConvert = (value: number | string): number => { +export const unitConvert = (value: number | string | null | undefined): number => { if (typeof value === 'string') { if (value.includes('rpx')) { return (parseInt(value, 10) * (systemInfo?.screenWidth ?? 750)) / 750; } return parseInt(value, 10); } - return value; + return value ?? 0; }; export const setIcon = (iconName, icon, defaultIcon) => { diff --git a/src/message/__test__/__snapshots__/index.test.js.snap b/src/message/__test__/__snapshots__/index.test.js.snap index 46b21c436..932e82255 100644 --- a/src/message/__test__/__snapshots__/index.test.js.snap +++ b/src/message/__test__/__snapshots__/index.test.js.snap @@ -15,7 +15,7 @@ exports[`message props : style && customStyle 1`] = ` ariaRole="alert" class="t-message class t-class t-message--warning " id="t-message_0" - style="z-index:15000;top:20px;right:32rpx;left:32rpx; color: red; font-size: 9px;" + style="z-index:15000;top:20px;left:20rpx;right:32rpx; color: red; font-size: 9px;" >