Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with can-slot not working with <self-closing/> components #189

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion can-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ var Component = Construct.extend(

// Add a hookup for each <can-slot>
options.tags['can-slot'] = makeInsertionTagCallback('can-slot', componentTagData, shadowTagData, leakScope, function(el) {
return componentTagData.templates[el.getAttribute("name")];
var templates = componentTagData.templates;
if (templates) {// This is undefined if the component is <self-closing/>
return templates[el.getAttribute("name")];
}
});

// Add a hookup for <content>
Expand Down
24 changes: 24 additions & 0 deletions test/component-slot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ test("<can-slot> Works with default content", function() {
equal(testView.firstChild.innerHTML, 'Default Content');
});

test("<can-slot> Works in a self-closing template", function() {
/* A component like <hello-world/> can be rendered like <hello-world></hello-world> */

var ViewModel = DefineMap.extend({});

Component.extend({
tag : 'my-email',
view : stache(
'<can-slot name="subject">' +
'Default Content' +
'</can-slot>'
),
ViewModel: ViewModel
});

var renderer = stache(
'<my-email/>'
);

var testView = renderer();

equal(testView.firstChild.innerHTML, 'Default Content');
});

test("<can-slot> Context one-way binding works", function() {
/*Passing in a custom context like <can-slot name='subject' {context}='value' />*/

Expand Down