Skip to content

Commit f222cb5

Browse files
authored
TransferList: Fix Transfer After Transfer All and Other Enhancements (#549)
* TransferList Fix Transfer After Transfer All and Other Enhancements * Some Fix
1 parent dcd8e98 commit f222cb5

File tree

10 files changed

+75
-24
lines changed

10 files changed

+75
-24
lines changed

CodeBeam.MudBlazor.Extensions.Docs.Wasm/wwwroot/CodeBeam.MudBlazor.Extensions.xml

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeBeam.MudBlazor.Extensions.Docs/Pages/Components/TransferList/Examples/TransferListExample1.razor

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<MudTransferList @ref="_transferList" T="string" @bind-StartCollection="_startCollection" @bind-EndCollection="_endCollection" Vertical="_vertical" Color="_color"
77
StyleListCommon="background-color: var(--mud-palette-background-gray); width: 200px" MultiSelection="_multiSelection" MaxItems="_maxItems" SelectAllType="_selectAllType"
88
PreventTransfer="@(new Func<bool, bool>(CheckTransfer))" OrderFunc="@(_orderOnTransfer == false ? null : new Func<ICollection<string>, ICollection<string>>(OrderMethod))" ButtonVariant="_buttonVariant"
9-
AllowDoubleClick="_allowDoubleClick" SearchBoxStart="_searchboxStart" SearchBoxEnd="_searchboxEnd"
9+
AllowDoubleClick="_allowDoubleClick" SearchBoxStart="_searchboxStart" SearchBoxEnd="_searchboxEnd" Dense="_dense"
1010
StartTitle="@_startTitle" EndTitle="@_endTitle" />
1111
</MudItem>
1212

@@ -21,6 +21,7 @@
2121
<MudSwitchM3 @bind-Value="_allowDoubleClick" Label="Allow Double Click" Color="Color.Secondary" />
2222
<MudSwitchM3 @bind-Value="_searchboxStart" Label="SearchBox Start" Color="Color.Secondary" />
2323
<MudSwitchM3 @bind-Value="_searchboxEnd" Label="SearchBox End" Color="Color.Secondary" />
24+
<MudSwitchM3 @bind-Value="_dense" Label="Dense" Color="Color.Secondary" />
2425
<MudNumericField @bind-Value="_maxItems" Clearable="true" Label="MaxItems" Variant="Variant.Outlined" Margin="Margin.Dense" />
2526
<MudSelectExtended @bind-Value="_selectAllType" ItemCollection="@(Enum.GetValues<SelectAllType>())" Label="SelectAll Type" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" />
2627
<MudSelectExtended @bind-Value="_color" ItemCollection="@(Enum.GetValues<Color>())" Label="Color" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true" />
@@ -36,19 +37,20 @@
3637
ICollection<string> _startCollection = new List<string>() { "Sweden", "Hungary", "Turkey", "England", "Egypt" };
3738
ICollection<string> _endCollection = new List<string>() { "Brazil", "China", "Germany", "USA", "South Africa" };
3839

39-
bool _vertical;
40-
bool _multiSelection;
41-
bool _preventTurkeyTransfer;
42-
bool _orderOnTransfer;
43-
bool _allowDoubleClick;
44-
bool _searchboxStart;
45-
bool _searchboxEnd;
46-
int? _maxItems;
47-
SelectAllType _selectAllType = SelectAllType.Buttons;
48-
Color _color = Color.Primary;
49-
Variant _buttonVariant = Variant.Text;
50-
string _startTitle = "Country Group 1";
51-
string _endTitle = "Country Group 2";
40+
private bool _vertical;
41+
private bool _multiSelection;
42+
private bool _preventTurkeyTransfer;
43+
private bool _orderOnTransfer;
44+
private bool _allowDoubleClick;
45+
private bool _searchboxStart;
46+
private bool _searchboxEnd;
47+
private bool _dense;
48+
private int? _maxItems;
49+
private SelectAllType _selectAllType = SelectAllType.Buttons;
50+
private Color _color = Color.Primary;
51+
private Variant _buttonVariant = Variant.Text;
52+
private string _startTitle = "Country Group 1";
53+
private string _endTitle = "Country Group 2";
5254

5355
private bool CheckTransfer(bool startToEnd)
5456
{

CodeBeam.MudBlazor.Extensions.UnitTests/Components/TransferListTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ public async Task TransferListTransferAllTest()
1414
var transferList = comp.FindComponent<MudTransferList<string>>();
1515
transferList.Instance.StartCollection.Should().Contain("Turkey");
1616
transferList.Instance.StartCollection.Should().NotContain("China");
17+
transferList?.Instance?.StartCollection?.Count.Should().Be(5);
18+
transferList?.Instance?.EndCollection?.Count.Should().Be(5);
1719
await comp.InvokeAsync(() => transferList.Instance.TransferAll(true));
1820
transferList.Instance.StartCollection.Should().NotContain("Turkey");
1921
transferList.Instance.EndCollection.Should().Contain("Turkey");
2022
await comp.InvokeAsync(() => transferList.Instance.TransferAll(false));
2123
transferList.Instance.StartCollection.Should().Contain("Turkey");
2224
transferList.Instance.EndCollection.Should().NotContain("Turkey");
25+
transferList?.Instance?.StartCollection?.Count.Should().Be(10);
26+
transferList?.Instance?.EndCollection?.Count.Should().Be(0);
2327
}
2428

2529
}

CodeBeam.MudBlazor.Extensions/Components/TransferList/MudTransferList.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
@typeparam T
44

55
<MudStack Class="@Class" Style="@Style" Row="!Vertical" Spacing="Spacing">
6-
<div>
6+
<div class="mud-transfer-list-container">
77
@if (StartTitleContent != null)
88
{
99
@StartTitleContent
@@ -12,7 +12,7 @@
1212
{
1313
<MudListItemExtended T="string"><MudText>@StartTitle</MudText></MudListItemExtended>
1414
}
15-
<MudListExtended @ref="_startList" Class="@StartClassname" Style="@StartStylename" SearchBox="SearchBoxStart" OnDoubleClick="DoubleClick" T="T" ItemCollection="@StartCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color" ToStringFunc="ToStringFunc">
15+
<MudListExtended @ref="_startList" Padding="@Padding" Class="@StartClassname" Style="@StartStylename" SearchBox="SearchBoxStart" OnDoubleClick="DoubleClick" T="T" ItemCollection="@StartCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color" ToStringFunc="ToStringFunc" Dense="@Dense">
1616
<SelectAllTemplate>
1717
@if (SelectAllType == SelectAllType.SelectAllItem)
1818
{
@@ -34,7 +34,7 @@
3434
<MudIconButton Icon="@(Vertical ? Icons.Material.Filled.KeyboardDoubleArrowUp : Icons.Material.Filled.KeyboardDoubleArrowLeft)" Disabled="Disabled" Color="@Color" Variant="@ButtonVariant" OnClick="@(() => TransferAll(false))" />
3535
}
3636
</div>
37-
<div>
37+
<div class="mud-transfer-list-container">
3838
@if (EndTitleContent != null)
3939
{
4040
@EndTitleContent
@@ -43,7 +43,7 @@
4343
{
4444
<MudListItemExtended T="string"><MudText>@EndTitle</MudText></MudListItemExtended>
4545
}
46-
<MudListExtended @ref="_endList" Class="@EndClassname" Style="@EndStylename" SearchBox="SearchBoxEnd" OnDoubleClick="DoubleClick" T="T" ItemCollection="@EndCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color" ToStringFunc="ToStringFunc">
46+
<MudListExtended @ref="_endList" Padding="@Padding" Class="@EndClassname" Style="@EndStylename" SearchBox="SearchBoxEnd" OnDoubleClick="DoubleClick" T="T" ItemCollection="@EndCollection" Disabled="Disabled" Clickable="true" MultiSelection="@MultiSelection" SelectAll="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MaxItems="@MaxItems" Color="@Color" ToStringFunc="ToStringFunc" Dense="@Dense">
4747
<SelectAllTemplate>
4848
@if (SelectAllType == SelectAllType.SelectAllItem)
4949
{

CodeBeam.MudBlazor.Extensions/Components/TransferList/MudTransferList.razor.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public partial class MudTransferList<T> : MudComponentBase
1616
/// <summary>
1717
///
1818
/// </summary>
19-
protected string? StartClassname => new CssBuilder()
19+
protected string? StartClassname => new CssBuilder("mud-transfer-list-common")
2020
.AddClass(ClassListCommon)
2121
.AddClass(ClassStartList)
2222
.Build();
2323

2424
/// <summary>
2525
///
2626
/// </summary>
27-
protected string? EndClassname => new CssBuilder()
27+
protected string? EndClassname => new CssBuilder("mud-transfer-list-common")
2828
.AddClass(ClassListCommon)
2929
.AddClass(ClassEndList)
3030
.Build();
@@ -119,11 +119,23 @@ public partial class MudTransferList<T> : MudComponentBase
119119
public string? EndTitle { get; set; }
120120

121121
/// <summary>
122-
///
122+
/// If true, the transfer list will be displayed vertically. Useful for narrow spaces or mobile devices.
123123
/// </summary>
124124
[Parameter]
125125
public bool Vertical { get; set; }
126126

127+
/// <summary>
128+
/// If true, adds top and bottom padding to the lists. Default is false.
129+
/// </summary>
130+
[Parameter]
131+
public bool Padding { get; set; }
132+
133+
/// <summary>
134+
///
135+
/// </summary>
136+
[Parameter]
137+
public bool Dense { get; set; }
138+
127139
/// <summary>
128140
///
129141
/// </summary>
@@ -357,6 +369,7 @@ protected internal async Task TransferAll(bool startToEnd = true)
357369
OrderItems();
358370
await EndCollectionChanged.InvokeAsync(EndCollection);
359371
await StartCollectionChanged.InvokeAsync(StartCollection);
372+
_startList.Clear();
360373
}
361374
else if (startToEnd == false)
362375
{
@@ -377,6 +390,7 @@ protected internal async Task TransferAll(bool startToEnd = true)
377390
OrderItems();
378391
await StartCollectionChanged.InvokeAsync(StartCollection);
379392
await EndCollectionChanged.InvokeAsync(EndCollection);
393+
_endList.Clear();
380394
}
381395
}
382396

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
.mud-transfer-list-common {
3+
height: fill-available;
4+
height: -webkit-fill-available;
5+
}
6+
7+
.mud-transfer-list-container {
8+
display: flex;
9+
flex-direction: column;
10+
flex: 1 1 0%;
11+
}

CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,15 @@
791791
.mud-typography-display-inline {
792792
display: inline; }
793793

794+
.mud-transfer-list-common {
795+
height: fill-available;
796+
height: -webkit-fill-available; }
797+
798+
.mud-transfer-list-container {
799+
display: flex;
800+
flex-direction: column;
801+
flex: 1 1 0%; }
802+
794803
/*@import '../abstracts/variables';*/
795804
.mud-list-extended {
796805
margin: 0;

CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CodeBeam.MudBlazor.Extensions/Styles/MudExtensions.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@import 'components/_switchm3';
1010
@import 'components/_wheel';
1111
@import 'components/_typographym3';
12+
@import 'components/_transferlist.scss';
1213

1314
@import 'components/_listextended';
1415
@import 'components/_selectextended';

CodeBeam.MudBlazor.Extensions/wwwroot/MudExtensions.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)