Skip to content

Commit 1009fef

Browse files
committed
fix(classname): fix zero mod value bug
1 parent 6d78a65 commit 1009fef

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/classname/classname.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export type Preset = {
4949
v?: string
5050
}
5151

52+
function isEmpty(val: string | boolean | number | undefined) {
53+
return !val && val !== 0
54+
}
55+
5256
/**
5357
* BEM className configure function.
5458
*
@@ -81,7 +85,7 @@ export function withNaming(preset: Preset): ClassNameInitilizer {
8185

8286
if (modVal === true) {
8387
className += modPrefix + k
84-
} else if (modVal) {
88+
} else if (!isEmpty(modVal)) {
8589
className += modPrefix + k + modValueDelimiter + modVal
8690
}
8791
}

packages/classname/test/classname.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('@bem-react/classname', () => {
4949

5050
test('zero', () => {
5151
const b = cn('Block')
52-
expect(b({ modName: '0' })).toEqual('Block Block_modName_0')
52+
expect(b({ modName: '0', mod: 0 })).toEqual('Block Block_modName_0 Block_mod_0')
5353
})
5454

5555
test('undefined', () => {
@@ -211,7 +211,7 @@ describe('@bem-react/classname', () => {
211211

212212
test('zero', () => {
213213
const b = cCn('block')
214-
expect(b({ modName: '0' })).toEqual('block block_modName_0')
214+
expect(b({ modName: '0', mod: 0 })).toEqual('block block_modName_0 block_mod_0')
215215
})
216216
})
217217
})

0 commit comments

Comments
 (0)