Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial button with Command feature (#124)
* Started work on Button CommandName, CommandArgument and OnCommand feature * Added Cascading Parent * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Update src/BlazorWebFormsComponents/BaseWebFormsComponent.cs Co-Authored-By: Egil Hansen <egil@assimilated.dk> * Updated with suggestions from @egil Co-authored-by: Egil Hansen <egil@assimilated.dk> * Fix #117 - Fix for Button Will not require StateHasChanged to trigger updates. Add Tests for Click and Command logic. * Removed extra console.writeline in the click event Co-authored-by: Mister Magoo <mister.magoo+githubsql@gmail.com> Co-authored-by: Egil Hansen <egil@assimilated.dk> Co-authored-by: Cody Merritt Anhorn <cody.anhorn@hotmail.com>
- Loading branch information
1 parent
8f5716f
commit 0db043a
Showing
15 changed files
with
1,150 additions
and
954 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,3 @@ | ||
# Button | ||
|
||
It may seem strange that we have a Button component when there already is an HTML button and Blazor has features that enable C# interactions with that button, but we need to activate other features that were once present in Web Forms |
37 changes: 37 additions & 0 deletions
37
samples/AfterBlazorServerSide/Pages/ControlSamples/Button/Index.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,37 @@ | ||
@page "/ControlSamples/Button" | ||
|
||
<h2>Button component home page</h2> | ||
|
||
<Button CommandName="Foo" CommandArgument="bar" OnCommand="OnCommand" OnClick="OnClick">Click me!</Button> | ||
|
||
<span style="font-weight: bold">@TheContent</span> | ||
|
||
@code { | ||
|
||
[Parameter] | ||
public string TheContent { get; set; } = "Not clicked yet!"; | ||
public string bar = "bar"; | ||
|
||
/* | ||
protected override void OnInitialized() { | ||
TheContent = "Initialized"; | ||
Console.WriteLine("Initialized"); | ||
} | ||
*/ | ||
|
||
void OnClick() { | ||
|
||
TheContent = "I've been clicked"; | ||
|
||
} | ||
|
||
void OnCommand(CommandEventArgs args) { | ||
|
||
Console.WriteLine("Command fired"); | ||
TheContent = $"Command '{args.CommandName}'"; | ||
|
||
} | ||
|
||
|
||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
src/BlazorWebFormsComponents.Test/BaseWebFormsComponent/Parent.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,41 @@ | ||
@inherits TestComponentBase | ||
|
||
<Fixture | ||
Test="FirstTest" | ||
> | ||
<ComponentUnderTest> | ||
@*<ListView Items="Widget.SimpleWidgetList" | ||
ItemType="Widget" | ||
Context="Item"> | ||
<ItemTemplate><span>@Item.Name</span></ItemTemplate> | ||
<LayoutTemplate Context="itemPlaceholder"> | ||
<div> | ||
<b>Header <Button @ref="MyButton">My Button</Button></b> | ||
<br/> | ||
@itemPlaceholder | ||
</div> | ||
</LayoutTemplate> | ||
</ListView> | ||
*@ | ||
|
||
<Button> | ||
<Button @ref="MyButton">My Button</Button> | ||
</Button> | ||
</ComponentUnderTest> | ||
</Fixture> | ||
|
||
@code { | ||
|
||
Button MyButton { get; set; } | ||
|
||
void FirstTest() { | ||
|
||
var cut = GetComponentUnderTest(); | ||
cut.FindAll("button").Count().ShouldNotBe(0); | ||
|
||
MyButton.ShouldNotBeNull(); | ||
MyButton.Parent.ShouldNotBeNull("Cannot find the Parent component"); | ||
|
||
} | ||
|
||
} |
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,37 @@ | ||
@inherits TestComponentBase | ||
|
||
|
||
<Fixture Test="FirstTest"> | ||
<ComponentUnderTest> | ||
<Button OnClick="OnClick">Click me!</Button> | ||
</ComponentUnderTest> | ||
</Fixture> | ||
|
||
|
||
@code { | ||
|
||
public string TheContent { get; set; } = "Not clicked yet!"; | ||
|
||
void OnClick() | ||
{ | ||
|
||
TheContent = "I've been clicked"; | ||
|
||
} | ||
|
||
void FirstTest() | ||
{ | ||
// Given | ||
var cut = GetComponentUnderTest(); | ||
|
||
TheContent.ShouldBe("Not clicked yet!"); | ||
|
||
// When | ||
cut.Find("button").Click(); | ||
|
||
// Then | ||
TheContent.ShouldBe("I've been clicked"); | ||
|
||
} | ||
|
||
} |
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,38 @@ | ||
@inherits TestComponentBase | ||
|
||
|
||
<Fixture Test="FirstTest"> | ||
<ComponentUnderTest> | ||
<Button CommandName="Foo" CommandArgument="CommandArgument" OnCommand="OnCommand">Click me!</Button> | ||
</ComponentUnderTest> | ||
</Fixture> | ||
|
||
|
||
@code { | ||
|
||
public string TheContent { get; set; } = "No Command yet!"; | ||
public string CommandArgument = "bar"; | ||
|
||
void OnCommand(CommandEventArgs args) | ||
{ | ||
|
||
TheContent = $"Command '{args.CommandName}' : '{args.CommandArgument.ToString()}'"; | ||
|
||
} | ||
|
||
void FirstTest() | ||
{ | ||
// Given | ||
var cut = GetComponentUnderTest(); | ||
|
||
TheContent.ShouldBe("No Command yet!"); | ||
|
||
// When | ||
cut.Find("button").Click(); | ||
|
||
// Then | ||
TheContent.ShouldBe("Command 'Foo' : 'bar'"); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.