Skip to content

Commit ee2ae35

Browse files
committed
fix vuejs#531 content fallback with multiple insertion points
1 parent 7e36468 commit ee2ae35

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/compile/transclude.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,19 @@ function transcludeContent (el) {
9494
var outlets = getOutlets(el)
9595
var i = outlets.length
9696
if (!i) return
97-
var outlet, select, j, main
97+
var outlet, select, selected, j, main
9898
// first pass, collect corresponding content
9999
// for each outlet.
100100
while (i--) {
101101
outlet = outlets[i]
102102
if (rawContent) {
103103
select = outlet.getAttribute('select')
104104
if (select) { // select content
105+
selected = rawContent.querySelectorAll(select)
105106
outlet.content = _.toArray(
106-
rawContent.querySelectorAll(select)
107+
selected.length
108+
? selected
109+
: outlet.childNodes
107110
)
108111
} else { // default content
109112
main = outlet

test/unit/specs/compile/transclude_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ if (_.inBrowser) {
7979
expect(res.firstChild.textContent).toBe('fallback')
8080
})
8181

82+
it('fallback content with multiple select', function () {
83+
el.innerHTML = '<p class="b">select b</p>'
84+
options.template = '<content select=".a"><p>fallback a</p></content><content select=".b">fallback b</content>'
85+
var res = transclude(el, options)
86+
expect(res.childNodes.length).toBe(2)
87+
expect(res.firstChild.textContent).toBe('fallback a')
88+
expect(res.lastChild.textContent).toBe('select b')
89+
})
90+
8291
it('content transclusion with replace', function () {
8392
el.innerHTML = '<p>hi</p>'
8493
options.template = '<div><div><content></content></div></div>'

0 commit comments

Comments
 (0)