File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
test/unit/specs/directives/element Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,14 @@ export function resolveSlots (vm, content) {
3838 contents [ name ] = extractFragment ( contents [ name ] , content )
3939 }
4040 if ( content . hasChildNodes ( ) ) {
41+ const nodes = content . childNodes
42+ if (
43+ nodes . length === 1 &&
44+ nodes [ 0 ] . nodeType === 3 &&
45+ ! nodes [ 0 ] . data . trim ( )
46+ ) {
47+ return
48+ }
4149 contents [ 'default' ] = extractFragment ( content . childNodes , content )
4250 }
4351}
Original file line number Diff line number Diff line change @@ -457,4 +457,23 @@ describe('Slot Distribution', function () {
457457 } )
458458 expect ( '"slot" attribute must be static' ) . toHaveBeenWarned ( )
459459 } )
460+
461+ it ( 'default slot should use fallback content if has only whitespace' , ( ) => {
462+ new Vue ( {
463+ el : el ,
464+ template : '<test><div slot="first">1</div> <div slot="second">2</div></test>' ,
465+ components : {
466+ test : {
467+ replace : true ,
468+ template :
469+ '<div class="wrapper">' +
470+ '<slot name="first"><p>first slot</p></slot>' +
471+ '<slot><p>this is the default slot</p></slot>' +
472+ '<slot name="second"><p>second named slot</p></slot>' +
473+ '</div>'
474+ }
475+ }
476+ } )
477+ expect ( el . children [ 0 ] . innerHTML ) . toBe ( '<div slot="first">1</div><p>this is the default slot</p><div slot="second">2</div>' )
478+ } )
460479} )
You can’t perform that action at this time.
0 commit comments