Skip to content

Commit

Permalink
[BUGFIX beta] Fix input macro params handling
Browse files Browse the repository at this point in the history
Before this PR, having a component with an `{{input}}` with bound type
would make that input only to work the first time it was rendered. This
was because the first param would be shifter from params, and that would
modify the params of the rest of the instances.

Fixes emberjs#16256
  • Loading branch information
Serabe committed Feb 27, 2018
1 parent c9b68d1 commit 51f09b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ember-glimmer/lib/syntax/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ export function inputMacro(_name: string, params: Option<WireFormat.Core.Params>
if (Array.isArray(typeArg)) {
// there is an AST plugin that converts this to an expression
// it really should just compile in the component call too.
let inputTypeExpr = params.shift() as WireFormat.Expression;
builder.dynamicComponent(inputTypeExpr, params, hash, true, null, null);
let inputTypeExpr = params[0] as WireFormat.Expression;
builder.dynamicComponent(inputTypeExpr, params.slice(1), hash, true, null, null);
return true;
}
if (typeArg === 'checkbox') {
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-glimmer/tests/integration/helpers/input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,22 @@ moduleFor('Helpers test: {{input}} with dynamic type', class extends InputRender

this.assertAttr('type', 'text');
}

['@test GH16256 input macro does not modify params in place']() {
this.registerComponent('my-input', {
template: `{{input type=inputType}}`
});

this.render(`{{my-input inputType=firstType}}{{my-input inputType=secondType}}`, {
firstType: 'password',
secondType: 'email'
});

let inputs = this.element.querySelectorAll('input');
this.assert.equal(inputs.length, 2, 'there are two inputs');
this.assert.equal(inputs[0].getAttribute('type'), 'password');
this.assert.equal(inputs[1].getAttribute('type'), 'email');
}
});

moduleFor(`Helpers test: {{input type='checkbox'}}`, class extends InputRenderingTest {
Expand Down

0 comments on commit 51f09b5

Please sign in to comment.