-
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.
Blazor integration for anchor menu item (#1123)
## π€¨ Rationale Blazor support for anchor menu item component ## π©βπ» Implementation Followed standard process. Includes test, update to example app, and update to README. ## π§ͺ Testing Tested via example app ## β Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed.
- Loading branch information
Showing
17 changed files
with
185 additions
and
189 deletions.
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
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-blazor-4fb13605-f140-4436-966d-6e247a30de5b.json
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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Blazor support for anchor menu item component", | ||
"packageName": "@ni/nimble-blazor", | ||
"email": "7282195+m-akinc@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
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
1 change: 1 addition & 0 deletions
1
packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchor.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@namespace NimbleBlazor | ||
@inherits NimbleAnchorBase | ||
<nimble-anchor | ||
href="@Href" | ||
hreflang="@HrefLang" | ||
|
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
1 change: 1 addition & 0 deletions
1
packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorButton.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@namespace NimbleBlazor | ||
@inherits NimbleAnchorBase | ||
<nimble-anchor-button | ||
href="@Href" | ||
hreflang="@HrefLang" | ||
|
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
14 changes: 14 additions & 0 deletions
14
packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorMenuItem.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,14 @@ | ||
@namespace NimbleBlazor | ||
@inherits NimbleAnchorBase | ||
<nimble-anchor-menu-item | ||
href="@Href" | ||
hreflang="@HrefLang" | ||
ping="@Ping" | ||
referrerpolicy="@ReferrerPolicy" | ||
rel="@Rel" | ||
target="@Target" | ||
type="@Type" | ||
disabled="@Disabled" | ||
@attributes="AdditionalAttributes"> | ||
@ChildContent | ||
</nimble-anchor-menu-item> |
24 changes: 24 additions & 0 deletions
24
packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorMenuItem.razor.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,24 @@ | ||
ο»Ώusing Microsoft.AspNetCore.Components; | ||
|
||
namespace NimbleBlazor; | ||
|
||
public partial class NimbleAnchorMenuItem : NimbleAnchorBase | ||
{ | ||
/// <summary> | ||
/// Whether the menu item is disabled. | ||
/// </summary> | ||
[Parameter] | ||
public bool? Disabled { get; set; } | ||
|
||
/// <summary> | ||
/// The child content of the element. | ||
/// </summary> | ||
[Parameter] | ||
public RenderFragment? ChildContent { get; set; } | ||
|
||
/// <summary> | ||
/// Any additional attributes that did not match known properties. | ||
/// </summary> | ||
[Parameter(CaptureUnmatchedValues = true)] | ||
public IDictionary<string, object>? AdditionalAttributes { get; set; } | ||
} |
1 change: 1 addition & 0 deletions
1
packages/nimble-blazor/NimbleBlazor/Components/NimbleAnchorTab.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@namespace NimbleBlazor | ||
@inherits NimbleAnchorBase | ||
<nimble-anchor-tab | ||
href="@Href" | ||
hreflang="@HrefLang" | ||
|
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,48 @@ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace NimbleBlazor; | ||
|
||
public abstract class NimbleAnchorBase : ComponentBase | ||
{ | ||
/// <summary> | ||
/// The URL the hyperlink references. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? Href { get; set; } | ||
|
||
/// <summary> | ||
/// Hints at the human language of the linked URL. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? HrefLang { get; set; } | ||
|
||
/// <summary> | ||
/// A space-separated list of URLs. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? Ping { get; set; } | ||
|
||
/// <summary> | ||
/// How much of the referrer to send when following the link. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? ReferrerPolicy { get; set; } | ||
|
||
/// <summary> | ||
/// The relationship of the linked URL as space-separated link types. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? Rel { get; set; } | ||
|
||
/// <summary> | ||
/// Where to display the linked URL, as the name for a browsing context. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? Target { get; set; } | ||
|
||
/// <summary> | ||
/// Hints at the linked URL's format with a MIME type. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a for more information. | ||
/// </summary> | ||
[Parameter] | ||
public string? Type { get; set; } | ||
} |
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
39 changes: 39 additions & 0 deletions
39
packages/nimble-blazor/Tests/NimbleBlazor.Tests/Unit/Components/NimbleAnchorMenuItemTests.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,39 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using Bunit; | ||
using Xunit; | ||
|
||
namespace NimbleBlazor.Tests.Unit.Components; | ||
|
||
/// <summary> | ||
/// Tests for <see cref="NimbleAnchorMenuItem"/>. | ||
/// </summary> | ||
public class NimbleAnchorMenuItemTests : NimbleAnchorBaseTests<NimbleAnchorMenuItem> | ||
{ | ||
[Fact] | ||
public void NimbleAnchorMenuItem_Render_HasAnchorMenuItemMarkup() | ||
{ | ||
var context = new TestContext(); | ||
context.JSInterop.Mode = JSRuntimeMode.Loose; | ||
var expectedMarkup = "nimble-anchor-menu-item"; | ||
|
||
var menuItem = context.RenderComponent<NimbleAnchorMenuItem>(); | ||
|
||
Assert.Contains(expectedMarkup, menuItem.Markup); | ||
} | ||
|
||
[Fact] | ||
public void AnchorMenuItemDisabled_AttributeIsSet() | ||
{ | ||
var anchorMenuItem = RenderWithPropertySet(x => x.Disabled, true); | ||
|
||
Assert.Contains("disabled", anchorMenuItem.Markup); | ||
} | ||
|
||
private IRenderedComponent<NimbleAnchorMenuItem> RenderWithPropertySet<TProperty>(Expression<Func<NimbleAnchorMenuItem, TProperty>> propertyGetter, TProperty propertyValue) | ||
{ | ||
var context = new TestContext(); | ||
context.JSInterop.Mode = JSRuntimeMode.Loose; | ||
return context.RenderComponent<NimbleAnchorMenuItem>(p => p.Add(propertyGetter, propertyValue)); | ||
} | ||
} |
Oops, something went wrong.