Skip to content

Commit

Permalink
fix: support text slots (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jun 13, 2018
1 parent 55d831f commit 93b8d98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/create-instance/add-slots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

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

function startsWithTag (str) {
return str && str.trim()[0] === '<'
}

function createVNodesForSlot (
h: Function,
slotValue: SlotValue,
name: string
): Array<VNode> {
): VNode | string {
if (typeof slotValue === 'string' &&
!startsWithTag(slotValue)) {
return slotValue
}

const el = typeof slotValue === 'string'
? compileToFunctions(slotValue)
: slotValue
Expand All @@ -19,7 +28,7 @@ function createVNodesForSlot (
export function createSlotVNodes (
h: Function,
slots: SlotsObject
): Array<VNode> {
): Array<VNode | string> {
return Object.keys(slots).reduce((acc, key) => {
const content = slots[key]
if (Array.isArray(content)) {
Expand Down
14 changes: 14 additions & 0 deletions test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ describeWithMountingMethods('options.slots', (mountingMethod) => {
}
})

it('mounts component with text slot', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: 'hello,',
header: 'world'
}
})
if (mountingMethod.name === 'renderToString') {
expect(wrapper).contains('hello,world')
} else {
expect(wrapper.text()).to.contain('hello,world')
}
})

it('mounts component with named slot if passed component in slot object', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
Expand Down

0 comments on commit 93b8d98

Please sign in to comment.