1
0
mirror of synced 2024-11-25 14:56:03 +03:00

Adds index support to default context

This commit is contained in:
Justin Schroeder 2020-05-09 23:01:02 -04:00
parent 27272e6582
commit a08163fba8
3 changed files with 26 additions and 3 deletions

View File

@ -11,7 +11,11 @@
:index="index"
:remove-item="removeItem"
>
<slot />
<FormulateSlot
:context="context"
:index="index"
name="default"
/>
</component>
</FormulateSlot>
</template>

View File

@ -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]
}

View File

@ -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: `
<FormulateInput
type="group"
name="test"
#default="{ name, index }"
:value="[{}, {}]"
>
<div class="repeatable">{{ name }}-{{ index }}</div>
</FormulateInput>
`,
})
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')
})
})