add ssr for group bindings

pull/4621/head
Jonniek 7 years ago committed by tanhauhau
parent 716d54571e
commit 7651abdeed

@ -110,7 +110,16 @@ export default function(node: Element, renderer: Renderer, options: RenderOption
} }
if (name === 'group') { if (name === 'group') {
// TODO server-render group bindings const value_attribute = node.attributes.find(({ name }) => name === 'value');
if (value_attribute && value_attribute.chunks.length === 1) {
const value = get_attribute_value(value_attribute);
const bound = expression.node;
renderer.add_expression(x`
${value} === ${bound} || Array.isArray(${bound}) && ${bound}.includes(${value})
? @add_attribute("checked", true, 1)
: ""
`);
}
} else if (contenteditable && (name === 'textContent' || name === 'innerHTML')) { } else if (contenteditable && (name === 'textContent' || name === 'innerHTML')) {
node_contents = expression.node; node_contents = expression.node;

@ -0,0 +1,5 @@
<div>Cheese</div>
<input type="radio" value="Plain" checked>
<input type="radio" value="Whole wheat">
<input type="checkbox" value="Beans">
<input type="checkbox" value="Cheese" checked>

@ -0,0 +1,12 @@
<script>
let tortilla = 'Plain';
let fillings = ['Cheese'];
</script>
<div>{fillings.toString()}</div>
<input type="radio" bind:group={tortilla} value="Plain">
<input type="radio" bind:group={tortilla} value="Whole wheat">
<input type="checkbox" bind:group={fillings} value="Beans">
<input type="checkbox" bind:group={fillings} value="Cheese">
Loading…
Cancel
Save