-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind to current-value instead of value.
- Loading branch information
1 parent
7a0ba9a
commit dbf9e93
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ace/Tests/NimbleBlazor.Tests.Acceptance/Pages.InteractiveServer/NumberFieldBindings.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@page "/InteractiveServer/NumberFieldBindings" | ||
@namespace NimbleBlazor.Tests.Acceptance.Pages | ||
@using System.Diagnostics.CodeAnalysis; | ||
@inherits LayoutComponentBase | ||
@rendermode @(new InteractiveServerRenderMode(prerender: false)) | ||
|
||
<NimbleNumberField id="number1" Value="_value1" ValueChanged="Value1Changed"></NimbleNumberField> | ||
<NimbleNumberField id="number2" Value="_value2" ValueChanged="Value2Changed"></NimbleNumberField> | ||
|
||
@code { | ||
private double _value1; | ||
private double _value2; | ||
|
||
private void Value1Changed(double? value) | ||
{ | ||
double newValue = value / 2 ?? 0; | ||
if (_value2 != newValue) | ||
{ | ||
_value2 = newValue; | ||
} | ||
} | ||
|
||
private void Value2Changed(double? value) | ||
{ | ||
double newValue = value * 2 ?? 0; | ||
if (_value1 != newValue) | ||
{ | ||
_value1 = newValue; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ce/Tests/NimbleBlazor.Tests.Acceptance/Tests.InteractiveServer/NumberFieldBindingTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using BlazorWorkspace.Testing.Acceptance; | ||
using Microsoft.Playwright; | ||
using Xunit; | ||
|
||
namespace NimbleBlazor.Tests.Acceptance.InteractiveServer; | ||
|
||
public class NumberFieldBindingTests : NimbleInteractiveAcceptanceTestsBase | ||
{ | ||
public NumberFieldBindingTests(PlaywrightFixture playwrightFixture, NimbleBlazorWebHostServerFixture blazorServerClassFixture) | ||
: base(playwrightFixture, blazorServerClassFixture) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task NumberField_TwoWayBindingsDontBreakAsync() | ||
{ | ||
await using (var pageWrapper = await NewPageForRouteAsync("InteractiveServer/NumberFieldBindings")) | ||
{ | ||
var page = pageWrapper.Page; | ||
var numberField1 = page.Locator("#number1"); | ||
var numberField1IncButton = numberField1.Locator("nimble-button", new LocatorLocatorOptions() { HasText = "Increment" }); | ||
var numberField2 = page.Locator("#number2"); | ||
var numberField2IncButton = numberField2.Locator("nimble-button", new LocatorLocatorOptions() { HasText = "Increment" }); | ||
|
||
await numberField1IncButton.ClickAsync(); | ||
await Assertions.Expect(numberField2).ToHaveAttributeAsync("current-value", "0.5"); | ||
await numberField2IncButton.ClickAsync(); | ||
await Assertions.Expect(numberField1).ToHaveAttributeAsync("current-value", "3"); // incrementing numberField2 to 1.5 should result in 3 for numberField1 | ||
} | ||
} | ||
} |