Skip to content

Commit 9099bd6

Browse files
committed
Merge pull request vuejs#787 from nkovacs/786-content-select-children
<content> select should only match children.
2 parents 8862bb6 + a3cdcac commit 9099bd6

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/compiler/transclude.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,14 @@ 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+
selected = _.toArray(selected).filter(function(node) {
92+
return node.parentNode === raw
93+
})
94+
}
95+
outlet.content = selected.length
96+
? selected
97+
: _.toArray(outlet.childNodes)
9598
} else { // default content
9699
main = outlet
97100
}

test/unit/specs/compiler/transclude_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,15 @@ 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><span><p class="c">nested c</p></span>'
114+
options.template = '<content select=".a"><p>fallback a</p></content><content select=".b">fallback b</content><content select=".c">fallback c</content>'
115+
var res = transclude(el, options)
116+
expect(res.childNodes.length).toBe(3)
117+
expect(res.firstChild.textContent).toBe('fallback a')
118+
expect(res.childNodes[1].textContent).toBe('select b')
119+
expect(res.lastChild.textContent).toBe('fallback c')
120+
})
121+
112122
})
113123
}

0 commit comments

Comments
 (0)