Skip to content

Commit

Permalink
🐛 fix(Sortable): the re-order should be triggered after the Order pro…
Browse files Browse the repository at this point in the history
…perty value changes (#2120)
  • Loading branch information
capdiem authored Aug 28, 2024
1 parent 489165f commit c039e19
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/Masa.Blazor/Components/Sortable/MSortableProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ public abstract class MSortableProviderBase<TItem> : MasaComponentBase, ISortabl

[Parameter] [EditorRequired] public IEnumerable<TItem> Items { get; set; } = Enumerable.Empty<TItem>();

[Parameter]
public List<string>? Order
{
get => GetValue<List<string>>();
set => SetValue(value);
}
[Parameter] public List<string>? Order { get; set; }

[Parameter] public EventCallback<List<string>> OrderChanged { get; set; }

Expand Down Expand Up @@ -178,6 +173,7 @@ public bool Disabled
private IEnumerable<TItem>? _prevItems;
private HashSet<string> _prevItemKeys;
private List<string> _internalOrder;
private string[] _prevOrder = [];

private DotNetObjectReference<SortableJSInteropHandle>? _sortableJSInteropHandle;
private SortableJSObjectReference? _jsObjectReference;
Expand Down Expand Up @@ -205,8 +201,7 @@ protected override void RegisterWatchers(PropertyWatcher watcher)
base.RegisterWatchers(watcher);

watcher.Watch<bool>(nameof(Disabled),
val => { _jsObjectReference?.InvokeVoidAsync("option", "disabled", val); })
.Watch<List<string>>(nameof(Order), val => { _ = _jsObjectReference?.SortAsync(val, false); });
val => { _jsObjectReference?.InvokeVoidAsync("option", "disabled", val); });
}

protected override void OnParametersSet()
Expand All @@ -232,6 +227,12 @@ protected override void OnParametersSet()
SortByInternalOrder();
}
}

if (Order is not null && !_prevOrder.SequenceEqual(Order))
{
_prevOrder = Order.ToArray();
_ = _jsObjectReference?.SortAsync(Order, false);
}
}

protected override async Task OnAfterRenderAsync(bool firstRender)
Expand Down

0 comments on commit c039e19

Please sign in to comment.