Skip to content
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
11 changes: 9 additions & 2 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { config } from './config'
import { MountingOptions, Slot } from './types'
import {
isFunctionalComponent,
isHTML,
isObjectComponent,
mergeGlobalProperties
} from './utils'
Expand Down Expand Up @@ -289,8 +290,14 @@ export function mount(
}

if (typeof slot === 'string') {
// slot is most probably a scoped slot string or a plain string
acc[name] = (props: VNodeProps) => h(processSlot(slot), props)
// if it is HTML we process and render it using h
if (isHTML(slot)) {
acc[name] = (props: VNodeProps) => h(processSlot(slot), props)
}
// otherwise it is just a string so we just return it as-is
else {
acc[name] = () => slot
}
return acc
}

Expand Down
14 changes: 14 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,17 @@ export function isFunctionalComponent(component: any) {
export function isObjectComponent(component: any) {
return typeof component !== 'function' && !isClassComponent(component)
}

// https://stackoverflow.com/questions/15458876/check-if-a-string-is-html-or-not/15458987#answer-15458968
export function isHTML(str: string) {
var a = document.createElement('div')
a.innerHTML = str

for (let c = a.childNodes, i = c.length; i--; ) {
if (c[i].nodeType == 1) {
return true
}
}

return false
}
1 change: 1 addition & 0 deletions tests/mountingOptions/slots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('slots', () => {
named: namedString
}
})
expect(wrapper.vm.$slots.default()[0].children).toBe(defaultString)
expect(wrapper.find('.default').text()).toBe(defaultString)
expect(wrapper.find('.named').text()).toBe(namedString)
})
Expand Down