diff --git a/packages/classname/classname.ts b/packages/classname/classname.ts index 7c460b03..e30cd93d 100644 --- a/packages/classname/classname.ts +++ b/packages/classname/classname.ts @@ -49,6 +49,10 @@ export type Preset = { v?: string } +function isEmpty(val: string | boolean | number | undefined) { + return !val && val !== 0 +} + /** * BEM className configure function. * @@ -81,7 +85,7 @@ export function withNaming(preset: Preset): ClassNameInitilizer { if (modVal === true) { className += modPrefix + k - } else if (modVal) { + } else if (!isEmpty(modVal)) { className += modPrefix + k + modValueDelimiter + modVal } } diff --git a/packages/classname/test/classname.test.ts b/packages/classname/test/classname.test.ts index 9c996cc9..5afc9a8c 100644 --- a/packages/classname/test/classname.test.ts +++ b/packages/classname/test/classname.test.ts @@ -49,7 +49,7 @@ describe('@bem-react/classname', () => { test('zero', () => { const b = cn('Block') - expect(b({ modName: '0' })).toEqual('Block Block_modName_0') + expect(b({ modName: '0', mod: 0 })).toEqual('Block Block_modName_0 Block_mod_0') }) test('undefined', () => { @@ -211,7 +211,7 @@ describe('@bem-react/classname', () => { test('zero', () => { const b = cCn('block') - expect(b({ modName: '0' })).toEqual('block block_modName_0') + expect(b({ modName: '0', mod: 0 })).toEqual('block block_modName_0 block_mod_0') }) }) })