Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render multiple default slots #861

Merged
merged 2 commits into from
Jul 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 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,19 @@ describeWithMountingMethods('options.slots', mountingMethod => {
}
)

it('supports multiple root nodes in default slot option', () => {
const wrapper = mountingMethod(ComponentWithSlots, {
slots: {
default: ['<time /><time />']
}
})
if (mountingMethod.name === 'renderToString') {
expect(wrapper).to.contain('<time></time><time></time>')
} else {
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