Adds index support to default context
This commit is contained in:
parent
27272e6582
commit
a08163fba8
@ -11,7 +11,11 @@
|
|||||||
:index="index"
|
:index="index"
|
||||||
:remove-item="removeItem"
|
:remove-item="removeItem"
|
||||||
>
|
>
|
||||||
<slot />
|
<FormulateSlot
|
||||||
|
:context="context"
|
||||||
|
:index="index"
|
||||||
|
name="default"
|
||||||
|
/>
|
||||||
</component>
|
</component>
|
||||||
</FormulateSlot>
|
</FormulateSlot>
|
||||||
</template>
|
</template>
|
||||||
|
@ -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 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
|
const { name, context, ...attrs } = data.attrs
|
||||||
return h('div', { ...data, ...{ attrs } }, children)
|
return h('div', { ...data, ...{ attrs } }, children)
|
||||||
|
|
||||||
// If there is only one child, render it alone
|
// 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]
|
return children[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,4 +377,23 @@ describe('FormulateInputGroup', () => {
|
|||||||
await form.vm.formSubmitted()
|
await form.vm.formSubmitted()
|
||||||
expect(wrapper.find('[data-classification="group"] > .formulate-input-errors').exists()).toBe(false)
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user