Skip to content

Commit 2256712

Browse files
authored
vue-vuetify: make rawChildErrors reactive
Fixes #2559
1 parent 4cb174d commit 2256712

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ export const useVuetifyArrayControl = <
479479
};
480480
});
481481

482+
const rawChildErrors = computed(() => input.control.value.childErrors);
483+
482484
return {
483485
...input,
484486
control: overwrittenControl,
@@ -487,7 +489,7 @@ export const useVuetifyArrayControl = <
487489
childLabelForIndex,
488490
computedLabel,
489491
vuetifyProps,
490-
rawChildErrors: input.control.value.childErrors,
492+
rawChildErrors,
491493
};
492494
};
493495

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, it, expect } from 'vitest';
2+
import type { ErrorObject } from 'ajv';
3+
import { computed, defineComponent, h, nextTick, provide, ref } from 'vue';
4+
import { mount } from '@vue/test-utils';
5+
import { useVuetifyArrayControl } from '../../../src/util/composition';
6+
7+
const makeError = (instancePath: string): ErrorObject => ({
8+
keyword: 'required',
9+
message: 'is required',
10+
instancePath,
11+
schemaPath: '#/required',
12+
params: {},
13+
});
14+
15+
describe('useVuetifyArrayControl', () => {
16+
it('exposes a reactive rawChildErrors that reflects child error changes', async () => {
17+
const childErrors = ref<ErrorObject[]>([]);
18+
19+
let captured: ReturnType<typeof useVuetifyArrayControl> | undefined;
20+
21+
const Child = defineComponent({
22+
setup() {
23+
const control = computed(() => ({
24+
label: '',
25+
required: false,
26+
config: {},
27+
uischema: { type: 'Control', scope: '#' },
28+
schema: { type: 'array' },
29+
data: [],
30+
childErrors: childErrors.value,
31+
i18nKeyPrefix: '',
32+
}));
33+
captured = useVuetifyArrayControl({ control });
34+
return () => h('div');
35+
},
36+
});
37+
38+
const Host = defineComponent({
39+
components: { Child },
40+
setup() {
41+
provide('jsonforms', {
42+
core: { data: {}, schema: {}, uischema: { type: 'Control' } },
43+
i18n: {
44+
translate: (_id: string, defaultMessage?: string) => defaultMessage,
45+
},
46+
});
47+
return () => h(Child);
48+
},
49+
});
50+
51+
mount(Host);
52+
53+
expect(captured).toBeDefined();
54+
expect(captured!.rawChildErrors.value).toEqual([]);
55+
56+
const next = [makeError('/0/name')];
57+
childErrors.value = next;
58+
await nextTick();
59+
60+
expect(captured!.rawChildErrors.value).toEqual(next);
61+
62+
const updated = [makeError('/0/name'), makeError('/1/name')];
63+
childErrors.value = updated;
64+
await nextTick();
65+
66+
expect(captured!.rawChildErrors.value).toEqual(updated);
67+
});
68+
});

0 commit comments

Comments
 (0)