File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -87,11 +87,14 @@ function transcludeContent (el, raw) {
87
87
select = outlet . getAttribute ( 'select' )
88
88
if ( select ) { // select content
89
89
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 )
95
98
} else { // default content
96
99
main = outlet
97
100
}
Original file line number Diff line number Diff line change @@ -109,5 +109,15 @@ if (_.inBrowser) {
109
109
expect ( res . childNodes [ 3 ] . tagName ) . toBe ( 'SPAN' )
110
110
} )
111
111
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
+
112
122
} )
113
123
}
You can’t perform that action at this time.
0 commit comments