Skip to content

Commit

Permalink
fix: render multiple children in default slot
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jul 28, 2018
1 parent aca7064 commit 3f31dcb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/create-instance/create-slot-vnodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ function createVNodesForSlot (
vm: Component,
slotValue: SlotValue,
name: string,
): VNode | string {
): VNode | Array<VNode> {
let vnode
if (typeof slotValue === 'string') {
const vnodes = createVNodes(vm, slotValue)
if (vnodes.length > 1) {
return vnodes
}
vnode = vnodes[0]
} else {
vnode = vm.$createElement(slotValue)
Expand All @@ -41,7 +44,7 @@ function createVNodesForSlot (
export function createSlotVNodes (
vm: Component,
slots: SlotsObject
): Array<VNode | string> {
): Array<VNode | Array<VNode>> {
return Object.keys(slots).reduce((acc, key) => {
const content = slots[key]
if (Array.isArray(content)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-instance/validate-slots.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function requiresTemplateCompiler (slot: any): void {
if (typeof slot === 'string' && !compileToFunctions) {
throwError(
`vueTemplateCompiler is undefined, you must pass ` +
`precompiled components if vue-template-compiler is ` +
`undefined`
`precompiled components if vue-template-compiler is ` +
`undefined`
)
}
}
Expand Down
3 changes: 0 additions & 3 deletions packages/test-utils/src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export default function mount (

const vm = parentVm.$mount(elm).$refs.vm

// Workaround for Vue < 2.5
vm._staticTrees = []

const componentsWithError = findAllVueComponentsFromVm(vm).filter(
c => c._error
)
Expand Down
9 changes: 9 additions & 0 deletions test/specs/mounting-options/slots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ describeWithMountingMethods('options.slots', mountingMethod => {
}
)

it('supports multiple root nodes in default slot option', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: ['<time /><time />']
}
})
expect(wrapper.findAll('time').length).to.equal(2)
})

itDoNotRunIf(
process.env.TEST_ENV === 'node',
'mounts component with named slot if passed string in slot object',
Expand Down

0 comments on commit 3f31dcb

Please sign in to comment.