Skip to content

Commit

Permalink
Merge pull request #4993 from Polymer/dom-if-slot
Browse files Browse the repository at this point in the history
Templatize: remove slots when hiding children
  • Loading branch information
Steve Orvell authored Jan 31, 2018
2 parents b52ab81 + 1463e3b commit 62fd4c5
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 70 deletions.
15 changes: 14 additions & 1 deletion lib/utils/templatize.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,20 @@
} else {
n.textContent = n.__polymerTextContent__;
}
} else if (n.style) {
// remove and replace slot
} else if (n.localName === 'slot') {
if (hide) {
n.__polymerReplaced__ = document.createComment('hidden-slot');
n.parentNode.replaceChild(n.__polymerReplaced__, n);
} else {
const replace = n.__polymerReplaced__;
if (replace) {
replace.parentNode.replaceChild(n, replace);
}
}
}

else if (n.style) {
if (hide) {
n.__polymerDisplay__ = n.style.display;
n.style.display = 'none';
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 class="stuff">stuff</div>
<slot id="one" name="one"></slot><template id="innerIf" is="dom-if" if restamp>hi</template>
<slot id="two" name="two"></slot>
{{text}}
<slot id="three" 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

0 comments on commit 62fd4c5

Please sign in to comment.