Skip to content

Commit facf7cb

Browse files
authored
fix(ButtonUpload): add ShowDeleteButton parameter (#7590)
* feat: add ShowDeleteButton paraemter * feat(ButtonUpload): add ShowDeleteButton parameter * test: 增加单元测试
1 parent 186d9ea commit facf7cb

11 files changed

Lines changed: 67 additions & 15 deletions

src/BootstrapBlazor/Components/Upload/ButtonUpload.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22
@typeparam TValue
33
@inherits FileListUploadBase<TValue>
44

@@ -17,7 +17,7 @@
1717
OnGetFileFormat="@OnGetFileFormat" OnCancel="OnCancel" CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
1818
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
1919
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
20-
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
20+
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
2121
</UploadPreviewList>
2222
}
2323
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange" />

src/BootstrapBlazor/Components/Upload/ButtonUpload.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
1313
/// </summary>
1414
public partial class ButtonUpload<TValue>
1515
{
16+
/// <summary>
17+
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 true</para>
18+
/// <para lang="en">Gets or sets whether to display the delete button. Default is true</para>
19+
/// </summary>
20+
[Parameter]
21+
public bool ShowDeleteButton { get; set; } = true;
22+
1623
/// <summary>
1724
/// <para lang="zh">获得/设置 浏览按钮加载中图标</para>
1825
/// <para lang="en">Gets or sets the loading icon for the browse button</para>

src/BootstrapBlazor/Components/Upload/CardUpload.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
ConfirmIcon="@DeleteConfirmButtonIcon"
7474
ConfirmButtonColor="DeleteConfirmButtonColor"
7575
ConfirmButtonText="@DeleteConfirmButtonText"
76-
CloseButtonText="@DeleteCloseButtonText"
76+
CloseButtonText="@DeleteCloseButtonText"
7777
Content="@DeleteConfirmContent"
7878
Icon="@RemoveIcon"
7979
IsAsync="true"

src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public partial class CardUpload<TValue>
5252

5353
private string PreviewerId => $"prev_{Id}";
5454

55+
/// <summary>
56+
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
57+
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
58+
/// </summary>
59+
[Parameter]
60+
public bool ShowDeleteButton { get; set; }
61+
5562
/// <summary>
5663
/// <para lang="zh">获得/设置 是否允许预览的回调方法,默认 null</para>
5764
/// <para lang="en">Gets or sets the callback method to determine whether preview is allowed. Default is null</para>

src/BootstrapBlazor/Components/Upload/DropUpload.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
CancelIcon="@CancelIcon" LoadingIcon="@LoadingIcon"
5656
InvalidStatusIcon="@InvalidStatusIcon" ValidStatusIcon="@ValidStatusIcon"
5757
ShowDownloadButton="@ShowDownloadButton" DownloadIcon="@DownloadIcon" OnDownload="@OnDownload"
58-
DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
58+
ShowDeleteButton="@ShowDeleteButton" DeleteIcon="@DeleteIcon" OnDelete="@OnFileDelete">
5959
</UploadPreviewList>
6060
}
6161
<InputFile AdditionalAttributes="@GetUploadAdditionalAttributes()" OnChange="OnFileChange"/>

src/BootstrapBlazor/Components/Upload/DropUpload.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ namespace BootstrapBlazor.Components;
1313
/// </summary>
1414
public partial class DropUpload
1515
{
16+
/// <summary>
17+
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 true</para>
18+
/// <para lang="en">Gets or sets whether to display the delete button. Default is true</para>
19+
/// </summary>
20+
[Parameter]
21+
public bool ShowDeleteButton { get; set; } = true;
22+
1623
/// <summary>
1724
/// <para lang="zh">获得/设置 Body 模板,默认 null。设置 BodyTemplate 后 IconTemplate 和 TextTemplate 不生效</para>
1825
/// <para lang="en">Gets or sets the body template. Default is null. When BodyTemplate is set, IconTemplate and TextTemplate are not effective</para>

src/BootstrapBlazor/Components/Upload/FileListUploadBase.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ namespace BootstrapBlazor.Components;
1212
/// <typeparam name="TValue"></typeparam>
1313
public class FileListUploadBase<TValue> : UploadBase<TValue>
1414
{
15-
/// <summary>
16-
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
17-
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
18-
/// </summary>
19-
[Parameter]
20-
public bool ShowDeleteButton { get; set; }
21-
2215
/// <summary>
2316
/// <para lang="zh">获得/设置 删除按钮图标</para>
2417
/// <para lang="en">Gets or sets the delete button icon</para>

src/BootstrapBlazor/Components/Upload/UploadPreviewList.razor

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@namespace BootstrapBlazor.Components
1+
@namespace BootstrapBlazor.Components
22

33
@if (Items != null)
44
{
@@ -32,7 +32,10 @@
3232
{
3333
<i class="@InvalidStatusIconString"></i>
3434
}
35-
<i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
35+
@if (ShowDeleteButton)
36+
{
37+
<i class="@DeleteIconString" @onclick:stopPropagation @onclick="@(e => OnFileDelete(item))"></i>
38+
}
3639
</div>
3740
}
3841
</div>

src/BootstrapBlazor/Components/Upload/UploadPreviewList.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public partial class UploadPreviewList
9696
[Parameter]
9797
public bool ShowDownloadButton { get; set; }
9898

99+
/// <summary>
100+
/// <para lang="zh">获得/设置 是否显示删除按钮,默认 false</para>
101+
/// <para lang="en">Gets or sets whether to display the delete button. Default is false</para>
102+
/// </summary>
103+
[Parameter]
104+
public bool ShowDeleteButton { get; set; }
105+
99106
/// <summary>
100107
/// <para lang="zh">获得/设置 点击下载按钮回调方法,默认 null</para>
101108
/// <para lang="en">Gets or sets the callback method for the download button click event. Default is null</para>

test/UnitTest/Components/UploadButtonTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,21 @@ public void ButtonUpload_Accept_Ok()
350350
cut.Contains("accept=\".jpg\"");
351351
}
352352

353+
[Theory]
354+
[InlineData(true, true)]
355+
[InlineData(false, false)]
356+
public void ShowDeleteButton_Ok(bool showDeleteButton, bool result)
357+
{
358+
var cut = Context.Render<ButtonUpload<string>>(pb =>
359+
{
360+
pb.Add(a => a.DefaultFileList, [new() { FileName = "1.csv" }]);
361+
pb.Add(a => a.ShowUploadFileList, true);
362+
pb.Add(a => a.ShowDeleteButton, showDeleteButton);
363+
});
364+
var exists = cut.Markup.Contains("delete-icon");
365+
Assert.Equal(result, exists);
366+
}
367+
353368
[Fact]
354369
public void ButtonUpload_OnGetFileFormat_Ok()
355370
{

0 commit comments

Comments
 (0)