Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/classname/classname.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export type Preset = {
v?: string
}

function isEmpty(val: string | boolean | number | undefined) {
return !val && val !== 0
}

/**
* BEM className configure function.
*
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/classname/test/classname.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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')
})
})
})
Expand Down