From be67e1226af977f2633448648122e0bbe483a065 Mon Sep 17 00:00:00 2001 From: Bassam Ismail Date: Thu, 25 Jun 2020 15:42:06 +0530 Subject: [PATCH] fix(4995): dynamiclly set autofocus --- .../render_dom/wrappers/Element/Attribute.ts | 4 ++-- test/runtime/samples/autofocus/_config.js | 20 +++++++++++++++++-- test/runtime/samples/autofocus/main.svelte | 18 ++++++++++++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts index 86b67ca47e37..1de7a0a19d22 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/Attribute.ts @@ -164,7 +164,7 @@ export default class AttributeWrapper { } // special case – autofocus. has to be handled in a bit of a weird way - if (this.node.is_true && name === 'autofocus') { + if (name === 'autofocus') { block.autofocus = element.var; } @@ -350,4 +350,4 @@ const boolean_attribute = new Set([ 'required', 'reversed', 'selected' -]); \ No newline at end of file +]); diff --git a/test/runtime/samples/autofocus/_config.js b/test/runtime/samples/autofocus/_config.js index faf9cf9f4813..75c55eabb052 100644 --- a/test/runtime/samples/autofocus/_config.js +++ b/test/runtime/samples/autofocus/_config.js @@ -1,8 +1,24 @@ export default { html: '', - test({ assert, component, target, window }) { + async test({ assert, component, target, window }) { component.visible = true; - assert.equal(target.querySelector('input'), window.document.activeElement); + const input = target.querySelector('input'); + async function dispatchEvent(value) { + input.value = value; + const inputEvent = new window.InputEvent("input"); + await input.dispatchEvent(inputEvent); + } + + assert.equal(window.document.activeElement.getAttribute('title'), 'text'); + + await dispatchEvent('dynamic'); + assert.equal(window.document.activeElement.getAttribute('title'), 'dynamic'); + + await dispatchEvent('bound'); + assert.equal(window.document.activeElement.getAttribute('title'), 'bound'); + + await dispatchEvent('fn'); + assert.equal(window.document.activeElement.getAttribute('title'), 'fn'); } }; diff --git a/test/runtime/samples/autofocus/main.svelte b/test/runtime/samples/autofocus/main.svelte index 561596e9cf4c..497e7918ec75 100644 --- a/test/runtime/samples/autofocus/main.svelte +++ b/test/runtime/samples/autofocus/main.svelte @@ -1,8 +1,16 @@ -{#if visible} - -{/if} \ No newline at end of file + + +{#if active === "text"} + +{:else if active === "dynamic"} + +{:else if active === "bound"} + +{:else if active === "fn"} + true} /> +{/if}