diff --git a/src/FormulateRepeatableProvider.vue b/src/FormulateRepeatableProvider.vue index f00bcc2..5ba0285 100644 --- a/src/FormulateRepeatableProvider.vue +++ b/src/FormulateRepeatableProvider.vue @@ -11,7 +11,11 @@ :index="index" :remove-item="removeItem" > - + diff --git a/src/FormulateSlot.js b/src/FormulateSlot.js index c1c321f..822aa8e 100644 --- a/src/FormulateSlot.js +++ b/src/FormulateSlot.js @@ -21,12 +21,12 @@ export default { } // If we found no scoped slot, take the children and render those inside a wrapper if there are multiple - if (children && (children.length > 1 || (forceWrap && children.length > 0))) { + if (Array.isArray(children) && (children.length > 1 || (forceWrap && children.length > 0))) { const { name, context, ...attrs } = data.attrs return h('div', { ...data, ...{ attrs } }, children) // If there is only one child, render it alone - } else if (children.length === 1) { + } else if (Array.isArray(children) && children.length === 1) { return children[0] } diff --git a/test/unit/FormulateInputGroup.test.js b/test/unit/FormulateInputGroup.test.js index ac6426c..e0a924c 100644 --- a/test/unit/FormulateInputGroup.test.js +++ b/test/unit/FormulateInputGroup.test.js @@ -377,4 +377,23 @@ describe('FormulateInputGroup', () => { await form.vm.formSubmitted() expect(wrapper.find('[data-classification="group"] > .formulate-input-errors').exists()).toBe(false) }) + + it('exposes the index to the context object on default slot', async () => { + const wrapper = mount({ + template: ` + +
{{ name }}-{{ index }}
+
+ `, + }) + const repeatables = wrapper.findAll('.repeatable') + expect(repeatables.length).toBe(2) + expect(repeatables.at(0).text()).toBe('test-0') + expect(repeatables.at(1).text()).toBe('test-1') + }) })