Skip to content

Commit

Permalink
Fix Target attribute on menus breaks HTML validation ,Fixes: OrchardC…
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzx86 committed Jun 18, 2024
1 parent 3d3f172 commit a2f0b26
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HtmlMenuItemPart : ContentPart
/// <summary>
/// The target of the link to create.
/// </summary>
public string Target { get; set; }
public string Target { get; set; } = "_self";

/// <summary>
/// The raw html to display for this link.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class LinkMenuItemPart : ContentPart
/// <summary>
/// The target of the link to create.
/// </summary>
public string Target { get; set; }
public string Target { get; set; } = "_self";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class HtmlMenuItemPartEditViewModel

public string Url { get; set; }

public string Target { get; set; }
public string Target { get; set; } = "_self";

public string Html { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LinkMenuItemPartEditViewModel

public string Url { get; set; }

public string Target { get; set; }
public string Target { get; set; } = "_self";

[BindNever]
public LinkMenuItemPart MenuItemPart { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
url = Url.Content(linkMenuItemPart.Url);
}

tag.Attributes["target"] = linkMenuItemPart.Target;
if (!string.IsNullOrEmpty(linkMenuItemPart.Target))
{
tag.Attributes["target"] = linkMenuItemPart.Target;
}

tag.Attributes["href"] = url;
tag.InnerHtml.Append(contentItem.DisplayText);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% assign link = Model.ContentItem.Content.HtmlMenuItemPart %}
<a class="nav-link" href="{{ link.Url | href }}" target="{{ link.Target }}">{{ link.Html | raw }}</a>
<a class="nav-link" href="{{ link.Url | href }}"{% if link.Target %} target="{{link.Target}}" {% endif %}>{{ link.Html | raw }}</a>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% assign link = Model.ContentItem.Content.LinkMenuItemPart %}
<a class="nav-link" href="{{ link.Url | href }}" target="{{ link.Target }}"
<a class="nav-link" href="{{ link.Url | href }}"{% if link.Target %} target="{{link.Target}}" {% endif %}
{% if link.Url contains "#" %}
data-bs-target="{{ link.Url | split: '/' | last }}"
{% endif %}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{% if Model.HasItems %}
<a href="{{ link.Url | href }}" class="nav-link px-lg-3 py-3 py-lg-4 dropdown-toggle" data-bs-toggle="dropdown">{{ link.Html | raw }}<b class="caret"></b></a>
{% else %}
<a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ link.Url | href }}" target="{{ link.Target }}">{{ link.Html | raw }}</a>
<a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ link.Url | href }}"{% if link.Target %} target="{{link.Target}}"{% endif %}>{{ link.Html | raw }}</a>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{% if Model.HasItems %}
<a href="{{ link.Url | href }}" class="nav-link px-lg-3 py-3 py-lg-4 dropdown-toggle" data-bs-toggle="dropdown">{{ Model.ContentItem.DisplayText }}<b class="caret"></b></a>
{% else %}
<a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ link.Url | href }} target="{{ link.Target }}">{{ Model.ContentItem.DisplayText }}</a>
<a class="nav-link px-lg-3 py-3 py-lg-4" href="{{ link.Url | href }}{% if link.Target %} target="{{link.Target}}"{% endif %}>{{ Model.ContentItem.DisplayText }}</a>
{% endif %}
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore.Navigation.Core/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MenuItem()
/// <summary>
/// The html target of the menu item.
/// </summary>
public string Target { get; set; }
public string Target { get; set; } = "_self";

/// <summary>
/// The optional url the menu item should link to.
Expand Down

0 comments on commit a2f0b26

Please sign in to comment.