Skip to content

Commit 345711a

Browse files
committed
update
1 parent 42d279e commit 345711a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/hooks/useStyleRegister.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import StyleContext, {
1515
ATTR_MARK,
1616
CSS_IN_JS_INSTANCE,
1717
} from '../StyleContext';
18-
import { isClientSide, isNullable, toStyleStr, where } from '../util';
18+
import { isClientSide, normalizeValue, toStyleStr, where } from '../util';
1919
import {
2020
CSS_FILE_STYLE,
2121
existPath,
@@ -324,8 +324,8 @@ export const parseStyle = (
324324
});
325325
} else {
326326
// 如果是 padding 属性,并且值为 undefined,则转换为 0
327-
if (key.startsWith('padding') && isNullable(actualValue)) {
328-
appendStyle(key, 0);
327+
if (key.startsWith('padding')) {
328+
appendStyle(key, normalizeValue(actualValue));
329329
} else {
330330
appendStyle(key, actualValue);
331331
}

src/util/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,7 @@ export function where(options?: {
204204
export const isNullable = <T>(val: T): val is Extract<T, null | undefined> => {
205205
return val === null || val === undefined;
206206
};
207+
208+
export const normalizeValue = <T>(val: T) => {
209+
return isNullable(val) ? 0 : val;
210+
};

0 commit comments

Comments
 (0)