Skip to content

Commit 4eccb8b

Browse files
authored
TransferList DoubleClick (#132)
1 parent 161ba02 commit 4eccb8b

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050
else
5151
{
52-
<MudListItemExtended Value="@item" Text="@(ToStringFunc == null ? item.ToString() : ToStringFunc(item))" />
52+
<MudListItemExtended Value="@item" @ondblclick="@(() => OnDoubleClickHandler(new MouseEventArgs(), item))" Text="@(ToStringFunc == null ? item.ToString() : ToStringFunc(item))" />
5353
}
5454
</MudVirtualize>
5555
}

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ public bool MultiSelection
324324
/// </summary>
325325
[Parameter] public EventCallback<FocusEventArgs> OnFocusOut { get; set; }
326326

327+
/// <summary>
328+
/// Fired on the OnDoubleClick event.
329+
/// </summary>
330+
[Parameter] public EventCallback<ListItemClickEventArgs<T>> OnDoubleClick { get; set; }
331+
327332
#endregion
328333

329334

@@ -1335,6 +1340,17 @@ public async Task ForceUpdate()
13351340
UpdateSelectedStyles();
13361341
}
13371342

1343+
protected async Task OnDoubleClickHandler(MouseEventArgs args, T itemValue)
1344+
{
1345+
await OnDoubleClick.InvokeAsync(new ListItemClickEventArgs<T>() { MouseEventArgs = args, ItemValue = itemValue});
1346+
}
1347+
13381348
#endregion
13391349
}
1350+
1351+
public class ListItemClickEventArgs<T>
1352+
{
1353+
public MouseEventArgs MouseEventArgs { get; set; }
1354+
public T ItemValue { get; set; }
1355+
}
13401356
}

CodeBeam.MudExtensions/Components/TransferList/MudTransferList.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@using MudExtensions.Enums
55

66
<MudStack Class="@Class" Style="@Style" Row="!Vertical" Spacing="Spacing">
7-
<MudListExtended @ref="_startList" Class="@StartClassname" Style="@StartStylename" T="T" ItemCollection="@StartCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
7+
<MudListExtended @ref="_startList" Class="@StartClassname" Style="@StartStylename" OnDoubleClick="DoubleClick" T="T" ItemCollection="@StartCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
88
<SelectAllTemplate>
99
@if (SelectAllType == SelectAllType.SelectAllItem)
1010
{
@@ -24,7 +24,7 @@
2424
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardDoubleArrowUp : Icons.Material.Filled.KeyboardDoubleArrowLeft)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => TransferAll(false))" />
2525
}
2626
</div>
27-
<MudListExtended @ref="_endList" Class="@EndClassname" Style="@EndStylename" T="T" ItemCollection="@EndCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
27+
<MudListExtended @ref="_endList" Class="@EndClassname" Style="@EndStylename" OnDoubleClick="DoubleClick" T="T" ItemCollection="@EndCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color">
2828
<SelectAllTemplate>
2929
@if (SelectAllType == SelectAllType.SelectAllItem)
3030
{

CodeBeam.MudExtensions/Components/TransferList/MudTransferList.razor.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public partial class MudTransferList<T> : MudComponentBase
7878
[Parameter]
7979
public bool Disabled { get; set; }
8080

81+
/// <summary>
82+
/// If true, double click transfers the item. Doesn't have any effect on multitransfer is true.
83+
/// </summary>
84+
[Parameter]
85+
public bool AllowDoubleClick { get; set; }
86+
8187
/// <summary>
8288
/// Allows the transfer multiple items at once.
8389
/// </summary>
@@ -295,5 +301,23 @@ protected void OrderItems()
295301
EndCollection = OrderFunc.Invoke(EndCollection);
296302
}
297303

304+
protected async Task DoubleClick(ListItemClickEventArgs<T> args)
305+
{
306+
if (AllowDoubleClick == false)
307+
{
308+
return;
309+
}
310+
311+
if (StartCollection != null && StartCollection.Contains(args.ItemValue))
312+
{
313+
await Transfer(true);
314+
}
315+
else if (EndCollection != null && EndCollection.Contains(args.ItemValue))
316+
{
317+
await Transfer(false);
318+
}
319+
320+
}
321+
298322
}
299323
}

ComponentViewer.Docs/Pages/Examples/TransferListExample1.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<MudItem xs="12" sm="8" Class="d-flex flex-column align-center justify-center">
55
<MudTransferList @ref="_transferList" T="string" @bind-StartCollection="_startCollection" @bind-EndCollection="_endCollection" Vertical="_vertical" Color="_color"
66
StyleListCommon="background-color: var(--mud-palette-background-grey); width: 200px" MultiSelection="_multiSelection" MaxItems="_maxItems" SelectAllType="_selectAllType"
7-
PreventTransfer="@(new Func<bool, bool>(CheckTransfer))" OrderFunc="@(_orderOnTransfer == false ? null : new Func<ICollection<string>, ICollection<string>>(OrderMethod))" ButtonVariant="_buttonVariant" />
7+
PreventTransfer="@(new Func<bool, bool>(CheckTransfer))" OrderFunc="@(_orderOnTransfer == false ? null : new Func<ICollection<string>, ICollection<string>>(OrderMethod))" ButtonVariant="_buttonVariant"
8+
AllowDoubleClick="_allowDoubleClick" />
89
</MudItem>
910

1011
<MudItem xs="12" sm="4">
@@ -15,6 +16,7 @@
1516
<MudSwitchM3 @bind-Checked="_multiSelection" Label="MultiSelection" Color="Color.Primary" />
1617
<MudSwitchM3 @bind-Checked="_preventTurkeyTransfer" Label="Prevent Transfer If Turkey Selected" Color="Color.Primary" />
1718
<MudSwitchM3 @bind-Checked="_orderOnTransfer" Label="Order on Transfer" Color="Color.Primary" />
19+
<MudSwitchM3 @bind-Checked="_allowDoubleClick" Label="Allow Double Click" Color="Color.Primary" />
1820
<MudNumericField @bind-Value="_maxItems" Clearable="true" Label="MaxItems" Variant="Variant.Outlined" Margin="Margin.Dense" />
1921
<MudSelectExtended @bind-Value="_selectAllType" ItemCollection="@(Enum.GetValues<SelectAllType>())" Label="SelectAll Type" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" />
2022
<MudSelectExtended @bind-Value="_color" ItemCollection="@(Enum.GetValues<Color>())" Label="Color" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" />
@@ -32,6 +34,7 @@
3234
bool _multiSelection;
3335
bool _preventTurkeyTransfer;
3436
bool _orderOnTransfer;
37+
bool _allowDoubleClick;
3538
int? _maxItems;
3639
SelectAllType _selectAllType = SelectAllType.Buttons;
3740
Color _color = Color.Primary;

ComponentViewer.Docs/Pages/Examples/TransferListExampleIntro.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<MudAlert Class="mud-width-full" Severity="Severity.Info"><b>Knowledge:</b> SelectAll Item only show on MultiSelection.</MudAlert>
55
<MudAlert Class="mud-width-full" Severity="Severity.Warning"><b>Limitation:</b> Null items should not use to transfer in MultiSelection.</MudAlert>
66
<MudAlert Class="mud-width-full" Severity="Severity.Warning"><b>Limitation:</b> Constant collections like arrays can not be use in MudTransferList.</MudAlert>
7+
<MudAlert Class="mud-width-full" Severity="Severity.Warning"><b>Limitation:</b> DoubleClick works only single transfer (not with multitransfer) and does not work with double touch for now.</MudAlert>
78
</MudGrid>

0 commit comments

Comments
 (0)