Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target attribute to Menu #15636

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

Add target attribute to Menu #15636

wants to merge 26 commits into from

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Apr 1, 2024

fixed: #15541

This PR allows the user to specify the target property on both the Menus and the AdminMenus

Menus

image
image

AdminMenus

image

@hyzx86 hyzx86 requested a review from agriffard as a code owner April 1, 2024 06:31
@hyzx86
Copy link
Contributor Author

hyzx86 commented Apr 1, 2024

Hi @MikeAlhayek ,It's ready for review.

@@ -24,6 +24,12 @@
<span class="hint">@T["The url of the link. A link will be shown only if it or one of their children have a url. The url will be relative to the root of the admin site"]</span>
</div>

<div class="mb-3">
<label asp-for="Target" class="form-label">@T["Target"]</label>
<input asp-for="Target" class="form-control" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select menu instead of of a text box. The options can be

Value: Text
_blank: Opens the linked document in a new window or tab
_self Opens: the linked document in the same frame as it was clicked (this is default)
_parent: Opens the linked document in the parent frame
_top: Opens the linked document in the full body of the window

Copy link
Contributor Author

@hyzx86 hyzx86 Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restricts users from using named window, such as those with a target attribute set to MyWorkflow, so clicking on any link if whose target is MyWorkflow will always use the same window

Not sure if OC has a text box similar to autocomplete, we can set the above options you mentioned as autocomplete options, while allowing the user to enter any custom content

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to create UI where anyone can use not just developers. Drop down menu will provide better user experience for the common use. What if we do a menu with "Other" options. When other is selected, we can show an input to provider the custom value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -15,6 +15,14 @@
</div>
</div>

<div class="@Orchard.GetWrapperClasses()">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select

@@ -14,3 +14,11 @@
<input asp-for="Url" class="form-control" />
</div>
</div>

<div class="@Orchard.GetWrapperClasses()">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select


if (!string.IsNullOrEmpty(htmlMenuItemPart.Target))
{
tag.Attributes["target"] = htmlMenuItemPart.Target;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate the value to make sure only valid values can be provided

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really not necessary, since the target attribute is freely definable, e.g. target="order_details" , and when the user clicks on a link it will always refresh the existing window as much as possible, instead of always opening a new one.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#target

@@ -1 +1 @@
<a href="@(Model.Href ?? "#")">@Model.Text</a>
<a href="@(Model.Href ?? "#")" @(!string.IsNullOrEmpty(Model.Target) ? $"target=\"" + Model.Target + "\"" : string.Empty)>@Model.Text</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can always add target attribute. Use _self as the default value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use the default values, there will be only one option here.
image

image

<a class="nav-link" href="{{ link.Url | href }}"{% if link.Target %} target="{{link.Target}}" {% endif %}>{{ link.Html | raw }}</a>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line at the end of the file and add target attribute by default with _self as default value

@@ -1,5 +1,5 @@
{% assign link = Model.ContentItem.Content.LinkMenuItemPart %}
<a class="nav-link" href="{{ link.Url | href }}"
<a class="nav-link" href="{{ link.Url | href }}"{% if link.Target %} target="{{link.Target}}" {% endif %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -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 }}">{{ 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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same. With line at the end of the file

@@ -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 }}">{{ 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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@hyzx86 hyzx86 marked this pull request as draft April 2, 2024 15:19
Copy link

This pull request has merge conflicts. Please resolve those before requesting a review.

@hyzx86 hyzx86 marked this pull request as ready for review May 10, 2024 10:27
@hyzx86 hyzx86 requested a review from MikeAlhayek May 10, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add target='_blank' to the Menus and AdminMenus
2 participants