-
-
Notifications
You must be signed in to change notification settings - Fork 385
feat(TreeView): add OnBeforeTreeItemClick parameter #7375
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
Changes from all commits
3254cee
4717aee
dc57b9d
f02261d
7697ffb
46f457f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -673,6 +673,7 @@ | |||||
| "TreeViewsTips6": "Set whether the node is <b>expanded</b> state through <code>TreeViewItem<TItem>.IsExpand</code>", | ||||||
| "TreeViewsTips7": "Set whether the node is <b>selected</b> state through <code>TreeViewItem<TItem>.IsActive</code>", | ||||||
| "TreeViewsTips8": "Through <code>TreeViewItem<TItem>.Checked</code>, set whether the node is in <b>checked/single selection</b> state", | ||||||
| "TreeViewsTipsOnBeforeTreeItemClick": "You can prevent a node click by setting the <code>OnBeforeTreeItemClick</code> callback method, and cancel the click action when it returns <code>false</code>.", | ||||||
|
||||||
| "TreeViewsTipsOnBeforeTreeItemClick": "You can prevent a node click by setting the <code>OnBeforeTreeItemClick</code> callback method, and cancel the click action when it returns <code>false</code>.", | |
| "TreeViewsTipsOnBeforeTreeItemClick": "Use the <code>OnBeforeTreeItemClick</code> callback to cancel a node click by returning <code>false</code>.", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone | ||
|
|
@@ -152,6 +152,12 @@ public partial class TreeView<TItem> : IModelEqualityComparer<TItem> | |
| [Parameter] | ||
| public Func<TreeViewItem<TItem>, Task>? OnTreeItemClick { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// 获得/设置 点击节点前回调方法 | ||
| /// </summary> | ||
| [Parameter] | ||
| public Func<TreeViewItem<TItem>, Task<bool>>? OnBeforeTreeItemClick { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the callback method when a tree item is checked. | ||
| /// </summary> | ||
|
|
@@ -379,7 +385,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender) | |
| await InvokeVoidAsync("scroll", Id, ScrollIntoViewOptions); | ||
| } | ||
|
|
||
| if(!firstRender && AllowDrag) | ||
| if (!firstRender && AllowDrag) | ||
| { | ||
| await InvokeVoidAsync("resetTreeViewRow", Id); | ||
| } | ||
|
|
@@ -590,24 +596,33 @@ private async Task<IEnumerable<IExpandableNode<TItem>>> GetChildrenRowAsync(Tree | |
|
|
||
| private async Task OnClick(TreeViewItem<TItem> item) | ||
| { | ||
| _activeItem = item; | ||
| if (ClickToggleNode && item.CanTriggerClickNode(IsDisabled, CanExpandWhenDisabled)) | ||
| var confirm = true; | ||
|
||
| if (OnBeforeTreeItemClick != null) | ||
| { | ||
| await OnToggleNodeAsync(item); | ||
| confirm = await OnBeforeTreeItemClick(item); | ||
| } | ||
|
|
||
| if (OnTreeItemClick != null) | ||
| if (confirm) | ||
| { | ||
| await OnTreeItemClick(item); | ||
| } | ||
| _activeItem = item; | ||
| if (ClickToggleNode && item.CanTriggerClickNode(IsDisabled, CanExpandWhenDisabled)) | ||
| { | ||
| await OnToggleNodeAsync(item); | ||
| } | ||
|
|
||
| if (ShowCheckbox && ClickToggleCheck) | ||
| { | ||
| var state = ToggleCheckState(item.CheckedState); | ||
| await OnCheckStateChanged(item, state); | ||
| } | ||
| if (OnTreeItemClick != null) | ||
| { | ||
| await OnTreeItemClick(item); | ||
| } | ||
|
|
||
| StateHasChanged(); | ||
| if (ShowCheckbox && ClickToggleCheck) | ||
| { | ||
| var state = ToggleCheckState(item.CheckedState); | ||
| await OnCheckStateChanged(item, state); | ||
| } | ||
|
|
||
| StateHasChanged(); | ||
| } | ||
| } | ||
|
|
||
| private async Task OnEnterAsync(string? searchText) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Description field contains Chinese text while other attributes in this file use English descriptions. This is inconsistent with the rest of the file where descriptions are in English. The Description should be translated to English to maintain consistency.