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

Templatize: remove slots when hiding children #4993

Merged
merged 7 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@
} else {
n.textContent = n.__polymerTextContent__;
}
// remove and replace slot
} else if (n.localName === 'slot') {
if (hide) {
n.__polymerParent__ = n.parentNode;
n.__polymerSibling__ = n.nextSibling;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the sibling was removed (e.g. due to dom-if going false) then the slot would never come back.

May be better to replaceChild with a non-slot?

n.parentNode.removeChild(n);
} else {
const parent = n.__polymerParent__;
if (parent) {
parent.insertBefore(n, n.__polymerSibling__ || null);
}
}
} else if (n.style) {
if (hide) {
n.__polymerDisplay__ = n.style.display;
Expand Down
22 changes: 22 additions & 0 deletions test/unit/dom-if-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,28 @@
</script>
</dom-module>

<dom-module id="x-slot">
<template>
<template id="domIf" is="dom-if" if>
<div>stuff</div>
<slot name="one"></slot>
<slot name="two"></slot>
{{text}}
<slot name="three"></slot>
</template>
</template>
<script>
Polymer({
is: 'x-slot',
properties: {
text: {
value: 'Stuff'
}
}
});
</script>
</dom-module>

<dom-module id="x-host">
<template>
<template id="domif" is="dom-if" if>
Expand Down
Loading