Skip to content

Commit 168d41e

Browse files
committed
feat: use scoped slot instead of slot
1 parent 66f24ef commit 168d41e

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Once submitted, an event 'formSubmitted' is emitted on $root with the formName a
3838
label: 'the label'
3939
}]
4040
```
41-
- [x] Named slot everywhere inside form
41+
- [x] Scoped slot everywhere inside form
4242
```js
43-
const formFields = [{ slot: 'nameOfTheSlot' }]
43+
const formFields = [{ slot: 'nameOfTheSlot', props: { foo: 'bar' } }]
4444
```
4545
- [x] Html directly inside json (formFields props)
4646
```js

src/App.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template lang="pug">
22
#app.section
3-
app-form(:btnReset="{value: 'Reset'}",
4-
:btnSubmit="{value: 'Submit'}",
3+
app-form(:btnReset="{ value: 'Reset' }",
4+
:btnSubmit="{ value: 'Submit' }",
55
:formFields="jsonFields",
66
formName="userProfil")
7-
div(slot="boxSlot")
7+
template(#boxSlot="{ prop }")
88
.box
99
article
1010
.content
1111
p
1212
strong.has-text-info Info<br>
1313
| You can also use
14-
strong named slot
14+
strong {{ prop }}
1515
| like this one
1616
</template>
1717

src/components/Form/Form.spec.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ describe('Form', () => {
7070
propsData: {
7171
formFields: fields,
7272
formName: FORM_NAME
73+
},
74+
scopedSlots: {
75+
boxSlot: '<p>{{ props.prop }}</p>'
7376
}
7477
})
7578
expect.extend(matchers(wrapper))
@@ -227,11 +230,14 @@ describe('Form', () => {
227230
expect(slotContainer).not.toBeADomElement()
228231
})
229232

230-
it('has a slot', () => {
233+
it('has a scoped slot', () => {
231234
expect(slotContainer).toBeADomElement()
232235

233236
const allSlots = wrapper.findAll(slotContainer)
234237
expect(allSlots).toHaveLength(1)
238+
239+
const { props: { prop } } = fields.find(field => Object.keys(field)[0] === 'slot')
240+
expect(allSlots.at(0).text()).toBe(prop)
235241
})
236242
})
237243

src/components/Form/Form.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.field(v-else-if="Object.keys(item).includes('slot')",
2121
v-bind="item.attr",
2222
data-test="slot")
23-
slot(:name="Object.values(item)[0]")
23+
slot(:name="item['slot']", v-bind="item.props")
2424

2525
.field(v-else, v-bind="item.field && item.field.attr")
2626
app-label(:item="item")

src/components/Form/fields.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@
125125
"isRequired": false
126126
},
127127
{
128-
"slot": "boxSlot"
128+
"slot": "boxSlot",
129+
"props": {
130+
"prop": "scoped slot"
131+
}
129132
},
130133
{
131134
"label": "Checkbox",

0 commit comments

Comments
 (0)