From 21fdbcd56232e939b4ce5b7872035f207a1b27f3 Mon Sep 17 00:00:00 2001
From: Ajay Bhargav Baaskaran
Date: Thu, 20 Jun 2019 14:36:53 -0700
Subject: [PATCH] Allow @bind-value to be specified on its own (#11401)
---
...ft.AspNetCore.Components.netstandard2.0.cs | 1 +
.../Components/src/BindAttributes.cs | 4 ++++
src/Components/test/E2ETest/Tests/BindTest.cs | 24 +++++++++++++++++++
.../BasicTestApp/BindCasesComponent.razor | 7 ++++++
4 files changed, 36 insertions(+)
diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
index f972cc5ecc..02ba2fa03e 100644
--- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
+++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs
@@ -20,6 +20,7 @@ namespace Microsoft.AspNetCore.Components
[Microsoft.AspNetCore.Components.BindElementAttribute("textarea", null, "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("checkbox", null, "checked", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute("text", null, "value", "onchange")]
+ [Microsoft.AspNetCore.Components.BindInputElementAttribute(null, "value", "value", "onchange")]
[Microsoft.AspNetCore.Components.BindInputElementAttribute(null, null, "value", "onchange")]
public static partial class BindAttributes
{
diff --git a/src/Components/Components/src/BindAttributes.cs b/src/Components/Components/src/BindAttributes.cs
index 3506b485fa..258ca0e1f0 100644
--- a/src/Components/Components/src/BindAttributes.cs
+++ b/src/Components/Components/src/BindAttributes.cs
@@ -15,6 +15,10 @@ namespace Microsoft.AspNetCore.Components
// when a specific type attribute is applied.
[BindInputElement(null, null, "value", "onchange")]
+ // Handles cases like - this is a fallback and will be ignored
+ // when a specific type attribute is applied.
+ [BindInputElement(null, "value", "value", "onchange")]
+
[BindInputElement("checkbox", null, "checked", "onchange")]
[BindInputElement("text", null, "value", "onchange")]
diff --git a/src/Components/test/E2ETest/Tests/BindTest.cs b/src/Components/test/E2ETest/Tests/BindTest.cs
index 4931dd786e..04aae5d5c2 100644
--- a/src/Components/test/E2ETest/Tests/BindTest.cs
+++ b/src/Components/test/E2ETest/Tests/BindTest.cs
@@ -81,6 +81,30 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Assert.Equal(string.Empty, mirrorValue.GetAttribute("value"));
}
+ [Fact]
+ public void CanBindTextbox_WithBindSuffixInitiallyPopulated()
+ {
+ var target = Browser.FindElement(By.Id("bind-with-suffix-textbox-initially-populated"));
+ var boundValue = Browser.FindElement(By.Id("bind-with-suffix-textbox-initially-populated-value"));
+ var mirrorValue = Browser.FindElement(By.Id("bind-with-suffix-textbox-initially-populated-mirror"));
+ var setNullButton = Browser.FindElement(By.Id("bind-with-suffix-textbox-initially-populated-setnull"));
+ Assert.Equal("Hello", target.GetAttribute("value"));
+ Assert.Equal("Hello", boundValue.Text);
+ Assert.Equal("Hello", mirrorValue.GetAttribute("value"));
+
+ // Modify target; verify value is updated and that textboxes linked to the same data are updated
+ target.Clear();
+ target.SendKeys("Changed value\t");
+ Browser.Equal("Changed value", () => boundValue.Text);
+ Assert.Equal("Changed value", mirrorValue.GetAttribute("value"));
+
+ // Remove the value altogether
+ setNullButton.Click();
+ Browser.Equal(string.Empty, () => target.GetAttribute("value"));
+ Assert.Equal(string.Empty, boundValue.Text);
+ Assert.Equal(string.Empty, mirrorValue.GetAttribute("value"));
+ }
+
[Fact]
public void CanBindTextArea_InitiallyBlank()
{
diff --git a/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor b/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
index a8b393660b..302145ba85 100644
--- a/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
+++ b/src/Components/test/testassets/BasicTestApp/BindCasesComponent.razor
@@ -15,6 +15,13 @@
+
+ Bind with value-suffix, Initially populated:
+
+ @textboxInitiallyPopulatedValue
+
+
+
Numeric Textboxes