File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import { config } from './config'
26
26
import { MountingOptions , Slot } from './types'
27
27
import {
28
28
isFunctionalComponent ,
29
+ isHTML ,
29
30
isObjectComponent ,
30
31
mergeGlobalProperties
31
32
} from './utils'
@@ -289,8 +290,14 @@ export function mount(
289
290
}
290
291
291
292
if ( typeof slot === 'string' ) {
292
- // slot is most probably a scoped slot string or a plain string
293
- acc [ name ] = ( props : VNodeProps ) => h ( processSlot ( slot ) , props )
293
+ // if it is HTML we process and render it using h
294
+ if ( isHTML ( slot ) ) {
295
+ acc [ name ] = ( props : VNodeProps ) => h ( processSlot ( slot ) , props )
296
+ }
297
+ // otherwise it is just a string so we just return it as-is
298
+ else {
299
+ acc [ name ] = ( ) => slot
300
+ }
294
301
return acc
295
302
}
296
303
Original file line number Diff line number Diff line change @@ -82,3 +82,17 @@ export function isFunctionalComponent(component: any) {
82
82
export function isObjectComponent ( component : any ) {
83
83
return typeof component !== 'function' && ! isClassComponent ( component )
84
84
}
85
+
86
+ // https://stackoverflow.com/questions/15458876/check-if-a-string-is-html-or-not/15458987#answer-15458968
87
+ export function isHTML ( str : string ) {
88
+ var a = document . createElement ( 'div' )
89
+ a . innerHTML = str
90
+
91
+ for ( let c = a . childNodes , i = c . length ; i -- ; ) {
92
+ if ( c [ i ] . nodeType == 1 ) {
93
+ return true
94
+ }
95
+ }
96
+
97
+ return false
98
+ }
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ describe('slots', () => {
15
15
named : namedString
16
16
}
17
17
} )
18
+ expect ( wrapper . vm . $slots . default ( ) [ 0 ] . children ) . toBe ( defaultString )
18
19
expect ( wrapper . find ( '.default' ) . text ( ) ) . toBe ( defaultString )
19
20
expect ( wrapper . find ( '.named' ) . text ( ) ) . toBe ( namedString )
20
21
} )
You can’t perform that action at this time.
0 commit comments