From f9b7d3622fc201b931df362c47ea6e08db771f68 Mon Sep 17 00:00:00 2001 From: pushkine Date: Sat, 18 Apr 2020 21:07:51 +0200 Subject: [PATCH 1/5] check value instead of risking stale state --- .../render_dom/wrappers/Element/Binding.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts index eca6e9d325b5..7f42fffa8a69 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts @@ -57,7 +57,7 @@ export default class BindingWrapper { this.is_readonly = this.node.is_readonly; - this.needs_lock = this.node.name === 'currentTime' || (parent.node.name === 'input' && parent.node.get_static_attribute_value('type') === 'number'); // TODO others? + this.needs_lock = this.node.name === 'currentTime' // TODO others? } get_dependencies() { @@ -93,11 +93,23 @@ export default class BindingWrapper { update_conditions.push(block.renderer.dirty(dependency_array)); } - if (parent.node.name === 'input') { - const type = parent.node.get_static_attribute_value('type'); - - if (type === null || type === "" || type === "text" || type === "email" || type === "password") { - update_conditions.push(x`${parent.var}.${this.node.name} !== ${this.snippet}`); + if (parent.node.name === "input") { + const type = parent.node.get_static_attribute_value("type"); + + if ( + type === null || + type === "" || + type === "text" || + type === "email" || + type === "password" + ) { + update_conditions.push( + x`${parent.var}.${this.node.name} !== ${this.snippet}` + ); + } else if (type === "number") { + update_conditions.push( + x`@to_number(${parent.var}.${this.node.name}) !== ${this.snippet}` + ); } } From a498613ec996df76adc7e3241bfaf9770889a66b Mon Sep 17 00:00:00 2001 From: pushkine Date: Sat, 18 Apr 2020 21:34:27 +0200 Subject: [PATCH 2/5] Missing semicolon --- src/compiler/compile/render_dom/wrappers/Element/Binding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts index 7f42fffa8a69..ac5732eae7b0 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Binding.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Binding.ts @@ -57,7 +57,7 @@ export default class BindingWrapper { this.is_readonly = this.node.is_readonly; - this.needs_lock = this.node.name === 'currentTime' // TODO others? + this.needs_lock = this.node.name === 'currentTime'; // TODO others? } get_dependencies() { From c057c57e742e8faa020bd0dd130b215885e9c19b Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 22 Apr 2020 17:48:51 +0200 Subject: [PATCH 3/5] tests --- .../samples/input-bind-number.solo/_config.js | 31 +++++++++++++++++++ .../input-bind-number.solo/main.svelte | 5 +++ 2 files changed, 36 insertions(+) create mode 100644 test/runtime/samples/input-bind-number.solo/_config.js create mode 100644 test/runtime/samples/input-bind-number.solo/main.svelte diff --git a/test/runtime/samples/input-bind-number.solo/_config.js b/test/runtime/samples/input-bind-number.solo/_config.js new file mode 100644 index 000000000000..a3510eb757ba --- /dev/null +++ b/test/runtime/samples/input-bind-number.solo/_config.js @@ -0,0 +1,31 @@ +export default { + test({ assert, target, window, component }) { + const input = target.querySelector("input"); + const inputEvent = new window.InputEvent("input"); + assert.equal(component.value, 5); + assert.equal(input.value, "5"); + + input.value = "5."; + input.dispatchEvent(inputEvent); + + // input type number has value === "" if ends with dot/comma + assert.equal(component.value, undefined); + assert.equal(input.value, ""); + + input.value = "5.5"; + input.dispatchEvent(inputEvent); + + assert.equal(component.value, 5.5); + assert.equal(input.value, "5.5"); + + input.value = "5.50"; + input.dispatchEvent(inputEvent); + + assert.equal(component.value, 5.5); + assert.equal(input.value, "5.50"); + + component.value = 1; + assert.equal(component.value, 1); + assert.equal(input.value, "1"); + }, +}; diff --git a/test/runtime/samples/input-bind-number.solo/main.svelte b/test/runtime/samples/input-bind-number.solo/main.svelte new file mode 100644 index 000000000000..7957e33229f1 --- /dev/null +++ b/test/runtime/samples/input-bind-number.solo/main.svelte @@ -0,0 +1,5 @@ + + + \ No newline at end of file From 6ad89f909109167be69ce0845948c447beb7b655 Mon Sep 17 00:00:00 2001 From: pushkine Date: Wed, 22 Apr 2020 17:50:56 +0200 Subject: [PATCH 4/5] remove test.solo --- .../{input-bind-number.solo => input-bind-number}/_config.js | 0 .../{input-bind-number.solo => input-bind-number}/main.svelte | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/runtime/samples/{input-bind-number.solo => input-bind-number}/_config.js (100%) rename test/runtime/samples/{input-bind-number.solo => input-bind-number}/main.svelte (100%) diff --git a/test/runtime/samples/input-bind-number.solo/_config.js b/test/runtime/samples/input-bind-number/_config.js similarity index 100% rename from test/runtime/samples/input-bind-number.solo/_config.js rename to test/runtime/samples/input-bind-number/_config.js diff --git a/test/runtime/samples/input-bind-number.solo/main.svelte b/test/runtime/samples/input-bind-number/main.svelte similarity index 100% rename from test/runtime/samples/input-bind-number.solo/main.svelte rename to test/runtime/samples/input-bind-number/main.svelte From 196ea3a1450372331e51b2f3cc75ffee93a48d13 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 23 Apr 2020 09:15:04 -0400 Subject: [PATCH 5/5] tidy --- .../{input-bind-number => binding-input-number-2}/_config.js | 0 test/runtime/samples/binding-input-number-2/main.svelte | 5 +++++ test/runtime/samples/input-bind-number/main.svelte | 5 ----- 3 files changed, 5 insertions(+), 5 deletions(-) rename test/runtime/samples/{input-bind-number => binding-input-number-2}/_config.js (100%) create mode 100644 test/runtime/samples/binding-input-number-2/main.svelte delete mode 100644 test/runtime/samples/input-bind-number/main.svelte diff --git a/test/runtime/samples/input-bind-number/_config.js b/test/runtime/samples/binding-input-number-2/_config.js similarity index 100% rename from test/runtime/samples/input-bind-number/_config.js rename to test/runtime/samples/binding-input-number-2/_config.js diff --git a/test/runtime/samples/binding-input-number-2/main.svelte b/test/runtime/samples/binding-input-number-2/main.svelte new file mode 100644 index 000000000000..62119547a04d --- /dev/null +++ b/test/runtime/samples/binding-input-number-2/main.svelte @@ -0,0 +1,5 @@ + + + diff --git a/test/runtime/samples/input-bind-number/main.svelte b/test/runtime/samples/input-bind-number/main.svelte deleted file mode 100644 index 7957e33229f1..000000000000 --- a/test/runtime/samples/input-bind-number/main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - \ No newline at end of file