Skip to content

Commit 93b8d98

Browse files
authored
fix: support text slots (#711)
1 parent 55d831f commit 93b8d98

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Diff for: packages/create-instance/add-slots.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22

33
import { compileToFunctions } from 'vue-template-compiler'
44

5+
function startsWithTag (str) {
6+
return str && str.trim()[0] === '<'
7+
}
8+
59
function createVNodesForSlot (
610
h: Function,
711
slotValue: SlotValue,
812
name: string
9-
): Array<VNode> {
13+
): VNode | string {
14+
if (typeof slotValue === 'string' &&
15+
!startsWithTag(slotValue)) {
16+
return slotValue
17+
}
18+
1019
const el = typeof slotValue === 'string'
1120
? compileToFunctions(slotValue)
1221
: slotValue
@@ -19,7 +28,7 @@ function createVNodesForSlot (
1928
export function createSlotVNodes (
2029
h: Function,
2130
slots: SlotsObject
22-
): Array<VNode> {
31+
): Array<VNode | string> {
2332
return Object.keys(slots).reduce((acc, key) => {
2433
const content = slots[key]
2534
if (Array.isArray(content)) {

Diff for: test/specs/mounting-options/slots.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
164164
}
165165
})
166166

167+
it('mounts component with text slot', () => {
168+
const wrapper = mountingMethod(ComponentWithSlots, {
169+
slots: {
170+
default: 'hello,',
171+
header: 'world'
172+
}
173+
})
174+
if (mountingMethod.name === 'renderToString') {
175+
expect(wrapper).contains('hello,world')
176+
} else {
177+
expect(wrapper.text()).to.contain('hello,world')
178+
}
179+
})
180+
167181
it('mounts component with named slot if passed component in slot object', () => {
168182
const wrapper = mountingMethod(ComponentWithSlots, {
169183
slots: {

0 commit comments

Comments
 (0)