Skip to content

Commit cfdfda3

Browse files
committed
<content> select should only match children.
Fixes 786
1 parent 635a6e7 commit cfdfda3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/compiler/transclude.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@ function transcludeContent (el, raw) {
8787
select = outlet.getAttribute('select')
8888
if (select) { // select content
8989
selected = raw.querySelectorAll(select)
90-
outlet.content = _.toArray(
91-
selected.length
92-
? selected
93-
: outlet.childNodes
94-
)
90+
if (selected.length) {
91+
outlet.content = _.toArray(selected).filter(function(element) {
92+
return element.parentNode === raw
93+
})
94+
} else {
95+
outlet.content = _.toArray(outlet.childNodes)
96+
}
9597
} else { // default content
9698
main = outlet
9799
}

test/unit/specs/compiler/transclude_spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,14 @@ if (_.inBrowser) {
109109
expect(res.childNodes[3].tagName).toBe('SPAN')
110110
})
111111

112+
it('select should only match children', function () {
113+
el.innerHTML = '<p class="b">select b</p><span><p class="b">nested b</p></span>'
114+
options.template = '<content select=".a"><p>fallback a</p></content><content select=".b">fallback b</content>'
115+
var res = transclude(el, options)
116+
expect(res.childNodes.length).toBe(2)
117+
expect(res.firstChild.textContent).toBe('fallback a')
118+
expect(res.lastChild.textContent).toBe('select b')
119+
})
120+
112121
})
113122
}

0 commit comments

Comments
 (0)