Allow @bind-value to be specified on its own (#11401)
This commit is contained in:
parent
e8181ae479
commit
21fdbcd562
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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")]
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue