Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected void NotifyAuthenticationStateChanged(System.Threading.Tasks.Task<Micr
[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
{
Expand Down
4 changes: 4 additions & 0 deletions src/Components/Components/src/BindAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ namespace Microsoft.AspNetCore.Components
// when a specific type attribute is applied.
[BindInputElement(null, null, "value", "onchange")]

// Handles cases like <input @bind-value="..." /> - 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")]

Expand Down
24 changes: 24 additions & 0 deletions src/Components/test/E2ETest/Tests/BindTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ public void CanBindTextbox_InitiallyPopulated()
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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
<input id="textbox-initially-populated-mirror" @bind="textboxInitiallyPopulatedValue" readonly />
<button id="textbox-initially-populated-setnull" @onclick="@(() => { textboxInitiallyPopulatedValue = null; })">Set null</button>
</p>
<p>
Bind with value-suffix, Initially populated:
<input id="bind-with-suffix-textbox-initially-populated" @bind-value="textboxInitiallyPopulatedValue" />
<span id="bind-with-suffix-textbox-initially-populated-value">@textboxInitiallyPopulatedValue</span>
<input type="text" id="bind-with-suffix-textbox-initially-populated-mirror" @bind-value="textboxInitiallyPopulatedValue" readonly />
<button id="bind-with-suffix-textbox-initially-populated-setnull" @onclick="@(() => { textboxInitiallyPopulatedValue = null; })">Set null</button>
</p>

<h2>Numeric Textboxes</h2>
<p>
Expand Down