Skip to content

Commit 243575c

Browse files
Nikita Steninyarastqt
Nikita Stenin
authored andcommitted
fix(classname): support mix via valueOf method
1 parent 9097e28 commit 243575c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/classname/classname.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ export function withNaming(preset: Preset): ClassNameInitilizer {
9292
const value = mix[i]
9393

9494
// Skipping non-string values and empty strings
95-
if (typeof value !== 'string' || !value) continue
95+
if (!value || typeof value.valueOf() !== 'string') continue
9696

97-
const mixes = value.split(' ')
97+
const mixes = value.valueOf().split(' ')
9898

9999
for (let j = 0; j < mixes.length; j++) {
100100
const val = mixes[j]

packages/classname/test/classname.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ describe('@bem-react/classname', () => {
128128
'Block-Elem Block-Elem_theme_normal Block-Elem_size_m',
129129
)
130130
})
131+
132+
test('object with valueOf', () => {
133+
const b = cn('Block')
134+
expect(b('Elem', null, [{ valueOf: () => 'Mix' } as string])).toEqual('Block-Elem Mix')
135+
})
131136
})
132137
})
133138

0 commit comments

Comments
 (0)