Skip to content

Commit c9e8cde

Browse files
authored
fix: element label in Vue array renderer
Replace `isNaN` with `Number.isNaN` to ensure accurate checks. `isNaN` returns true for most text values, leading to missing labels in the Vue array renderer. closes #2157
1 parent 90d5db2 commit c9e8cde

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

packages/vue-vanilla/src/util/composition.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ export const useVanillaArrayControl = <I extends { control: any }>(
120120
input.control.value.data,
121121
composePaths(`${index}`, childLabelProp)
122122
);
123-
if (labelValue === undefined || labelValue === null || isNaN(labelValue)) {
123+
if (
124+
labelValue === undefined ||
125+
labelValue === null ||
126+
Number.isNaN(labelValue)
127+
) {
124128
return '';
125129
}
126130
return `${labelValue}`;

packages/vue-vanilla/tests/unit/array/ArrayListRenderer.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,42 @@ const uischema = {
1818
},
1919
};
2020

21+
const schemaWithNameAndRate = {
22+
type: 'array',
23+
title: 'My Array',
24+
maxItems: 3,
25+
minItems: 1,
26+
items: {
27+
type: 'object',
28+
properties: {
29+
name: {
30+
type: 'string',
31+
},
32+
rate: {
33+
type: 'number',
34+
},
35+
},
36+
},
37+
};
38+
39+
const schemaWithCountAndName = {
40+
type: 'array',
41+
title: 'My Array',
42+
maxItems: 3,
43+
minItems: 1,
44+
items: {
45+
type: 'object',
46+
properties: {
47+
count: {
48+
type: 'number',
49+
},
50+
name: {
51+
type: 'string',
52+
},
53+
},
54+
},
55+
};
56+
2157
describe('ArrayListRenderer.vue', () => {
2258
it('renders a fieldset', () => {
2359
const wrapper = mountJsonForms(['a'], schema, uischema);
@@ -88,4 +124,44 @@ describe('ArrayListRenderer.vue', () => {
88124
expect(type).to.equal('button');
89125
}
90126
});
127+
128+
it('compute default label', async () => {
129+
const wrapper = mountJsonForms(
130+
[{ name: 'name1', rate: 5 }],
131+
schemaWithNameAndRate,
132+
uischema
133+
);
134+
const labels = wrapper.findAll('.array-list-item-label');
135+
const labelText = labels[0].text();
136+
expect(labelText).to.equal('name1');
137+
});
138+
139+
it('compute default label with undefined', async () => {
140+
const wrapper = mountJsonForms([{}], schemaWithNameAndRate, uischema);
141+
const labels = wrapper.findAll('.array-list-item-label');
142+
const labelText = labels[0].text();
143+
expect(labelText).to.equal('');
144+
});
145+
146+
it('compute default label with number', async () => {
147+
const wrapper = mountJsonForms(
148+
[{ count: 1, name: 'name1' }],
149+
schemaWithCountAndName,
150+
uischema
151+
);
152+
const labels = wrapper.findAll('.array-list-item-label');
153+
const labelText = labels[0].text();
154+
expect(labelText).to.equal('1');
155+
});
156+
157+
it('compute default label with NaN', async () => {
158+
const wrapper = mountJsonForms(
159+
[{ count: Number(undefined), name: 'name1' }],
160+
schemaWithCountAndName,
161+
uischema
162+
);
163+
const labels = wrapper.findAll('.array-list-item-label');
164+
const labelText = labels[0].text();
165+
expect(labelText).to.equal('');
166+
});
91167
});

0 commit comments

Comments
 (0)