Skip to content

Commit 4b55142

Browse files
fix: remove superfluous spaces when normalizing class (#3083)
Co-authored-by: Jacek Karczmarczyk <[email protected]>
1 parent 49bc2e4 commit 4b55142

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { normalizeClass } from '../src'
2+
3+
describe('normalizeClass', () => {
4+
test('handles string correctly', () => {
5+
expect(normalizeClass('foo')).toEqual('foo')
6+
})
7+
8+
test('handles array correctly', () => {
9+
expect(normalizeClass(['foo', undefined, true, false, 'bar'])).toEqual('foo bar')
10+
})
11+
12+
test('handles object correctly', () => {
13+
expect(normalizeClass({ foo: true, bar: false, baz: true })).toEqual(
14+
'foo baz'
15+
)
16+
})
17+
})

packages/shared/src/normalizeProp.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export function normalizeClass(value: unknown): string {
6262
res = value
6363
} else if (isArray(value)) {
6464
for (let i = 0; i < value.length; i++) {
65-
res += normalizeClass(value[i]) + ' '
65+
const normalized = normalizeClass(value[i])
66+
if (normalized) {
67+
res += normalized + ' '
68+
}
6669
}
6770
} else if (isObject(value)) {
6871
for (const name in value) {

0 commit comments

Comments
 (0)