From ef3db51bbf53aa9c7aad4ddb3e4ec57b4cb65fdc Mon Sep 17 00:00:00 2001 From: Ryouko Konpaku <36291250+RyoukoKonpaku@users.noreply.github.com> Date: Fri, 30 Mar 2018 17:10:23 +0800 Subject: [PATCH] Text Area Bind Fix for issue #434 (#439) * Text Area Bind Fix for issue #434 * Correct Typo/Mispelling on test method name. --- .../src/Rendering/BrowserRenderer.ts | 1 + .../Tests/BindTest.cs | 29 +++++++++++++++++++ .../BasicTestApp/BindCasesComponent.cshtml | 15 ++++++++++ 3 files changed, 45 insertions(+) diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Rendering/BrowserRenderer.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Rendering/BrowserRenderer.ts index d0da6c1965..495f9f2a9b 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Rendering/BrowserRenderer.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Rendering/BrowserRenderer.ts @@ -228,6 +228,7 @@ export class BrowserRenderer { switch (element.tagName) { case 'INPUT': case 'SELECT': + case 'TEXTAREA': if (isCheckbox(element)) { (element as HTMLInputElement).checked = value === 'True'; } else { diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/BindTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/BindTest.cs index 8c20996df0..1304d54b29 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/BindTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/BindTest.cs @@ -47,6 +47,35 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests target.SendKeys("Changed value\t"); Assert.Equal("Changed value", boundValue.Text); } + + [Fact] + public void CanBindTextArea_InitiallyBlank() + { + var target = Browser.FindElement(By.Id("textarea-initially-blank")); + var boundValue = Browser.FindElement(By.Id("textarea-initially-blank-value")); + Assert.Equal(string.Empty, target.GetAttribute("value")); + Assert.Equal(string.Empty, boundValue.Text); + + // Modify target; verify value is updated + target.SendKeys("Changed value"); + Assert.Equal(string.Empty, boundValue.Text); // Don't update as there's no change event fired yet. + target.SendKeys("\t"); + Assert.Equal("Changed value", boundValue.Text); + } + + [Fact] + public void CanBindTextArea_InitiallyPopulated() + { + var target = Browser.FindElement(By.Id("textarea-initially-populated")); + var boundValue = Browser.FindElement(By.Id("textarea-initially-populated-value")); + Assert.Equal("Hello", target.GetAttribute("value")); + Assert.Equal("Hello", boundValue.Text); + + // Modify target; verify value is updated + target.Clear(); + target.SendKeys("Changed value\t"); + Assert.Equal("Changed value", boundValue.Text); + } [Fact] public void CanBindCheckbox_InitiallyUnchecked() diff --git a/test/testapps/BasicTestApp/BindCasesComponent.cshtml b/test/testapps/BasicTestApp/BindCasesComponent.cshtml index fbb6d3b739..86a418ae42 100644 --- a/test/testapps/BasicTestApp/BindCasesComponent.cshtml +++ b/test/testapps/BasicTestApp/BindCasesComponent.cshtml @@ -10,6 +10,18 @@ @textboxInitiallyPopulatedValue
++ Initially blank: + + @textAreaIntiallyBlankValue +
++ Initially populated: + + @textAreaIntiallyPopulatedValue +
+Initially unchecked: @@ -41,6 +53,9 @@ string textboxInitiallyBlankValue = null; string textboxInitiallyPopulatedValue = "Hello"; + string textAreaIntiallyBlankValue = null; + string textAreaIntiallyPopulatedValue = "Hello"; + bool checkboxInitiallyUncheckedValue = false; bool checkboxInitiallyCheckedValue = true;