Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/BootstrapBlazor/Components/Upload/InputUpload.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace BootstrapBlazor.Components
@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits UploadBase<TValue>

Expand All @@ -12,9 +12,27 @@
placeholder="@PlaceHolder" value="@CurrentValueAsString" />
@if (ShowDeleteButton)
{
<Button class="@RemoveButtonClassString" IsDisabled="@IsDeleteButtonDisabled"
Icon="@DeleteButtonIcon" Text="@DeleteButtonText" Color="Color.None"
OnClick="@TriggerDeleteFile"></Button>
@if (ShowDeleteConfirmButton)
{
<PopConfirmButton Placement="Placement.Top" class="@RemoveButtonClassString"
ConfirmIcon="@DeleteConfirmButtonIcon"
ConfirmButtonColor="DeleteConfirmButtonColor"
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
ConfirmButtonText="@DeleteConfirmButtonText"
CloseButtonText="@DeleteCloseButtonText"
Content="@DeleteConfirmContent"
Text="@DeleteButtonText"
Icon="@DeleteButtonIcon"
IsDisabled="@IsDeleteButtonDisabled"
IsAsync="true"
OnConfirm="@(async ()=> await TriggerDeleteFile())" />
}
else
{
<Button class="@RemoveButtonClassString" IsDisabled="@IsDeleteButtonDisabled"
Icon="@DeleteButtonIcon" Text="@DeleteButtonText" Color="Color.None"
OnClick="@TriggerDeleteFile"></Button>
}

}
<Button class="@BrowserButtonClassString" IsDisabled="@CheckStatus()" Icon="@BrowserButtonIcon"
Text="@BrowserButtonText" Color="Color.None"></Button>
Expand Down
44 changes: 43 additions & 1 deletion src/BootstrapBlazor/Components/Upload/InputUpload.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public partial class InputUpload<TValue>
/// <para lang="en">Gets or sets the delete button icon</para>
/// </summary>
[Parameter]
public string? DeleteButtonIcon { get; set; }
public string? DeleteButtonIcon { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除按钮显示文字</para>
Expand All @@ -64,6 +64,48 @@ public partial class InputUpload<TValue>
[Parameter]
public bool ShowDeleteButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除前是否显示确认对话框,依赖 ShowDeleteButton 属性为 true 时有效</para>
/// <para lang="en">Gets or sets whether to display a confirmation dialog before deletion. Only takes effect when the ShowDeleteButton property is true</para>
/// </summary>
[Parameter]
public bool ShowDeleteConfirmButton { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮图标,默认 null</para>
/// <para lang="en">Gets or sets the confirmation button icon in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteConfirmButtonIcon { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮颜色,默认 Color.Danger</para>
/// <para lang="en">Gets or sets the color of the confirmation button in the delete confirmation dialog. Default is Color.Danger</para>
/// </summary>
[Parameter]
public Color DeleteConfirmButtonColor { get; set; } = Color.Danger;

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认按钮显示文字,默认 null</para>
/// <para lang="en">Gets or sets the confirmation button display text in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteConfirmButtonText { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中取消按钮显示文字,默认 null</para>
/// <para lang="en">Gets or sets the cancel button display text in the delete confirmation dialog. Default is null</para>
/// </summary>
[Parameter]
public string? DeleteCloseButtonText { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 删除确认弹窗中确认文本内容,默认 null 使用资源文件中内置文字</para>
/// <para lang="en">Gets or sets the confirmation text content in the delete confirmation dialog. Default is null (uses built-in text from resource file)</para>
/// </summary>
[Parameter]
public string? DeleteConfirmContent { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 PlaceHolder 占位符文本</para>
/// <para lang="en">Gets or sets the placeholder text</para>
Expand Down
26 changes: 26 additions & 0 deletions test/UnitTest/Components/UploadInputTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
cut.WaitForAssertion(() => cut.Contains("btn btn-delete"));
}

[Fact]
public async Task ShowConfirmButton_Ok()
{
var cut = Context.Render<InputUpload<string>>(pb =>
{
pb.Add(a => a.DefaultFileList,
[
new() { FileName = "test.png" }
]);
pb.Add(a => a.ShowDeleteButton, true);
pb.Add(a => a.ShowDeleteConfirmButton, true);
pb.Add(a => a.DeleteConfirmButtonColor, Color.Danger);
pb.Add(a => a.DeleteConfirmButtonIcon, "icon-delete");
pb.Add(a => a.DeleteConfirmContent, "content-delete");
pb.Add(a => a.DeleteConfirmButtonText, "confirm");
pb.Add(a => a.DeleteCloseButtonText, "cancel");
});

var button = cut.FindComponent<PopConfirmButton>();
Assert.NotNull(button);
Assert.NotNull(button.Instance.OnConfirm);

await cut.InvokeAsync(button.Instance.OnConfirm);
Comment thread
ArgoZhang marked this conversation as resolved.
}

[Fact]
public async Task InputUpload_ValidateForm_Ok()
{
Expand Down Expand Up @@ -209,6 +234,7 @@ await cut.InvokeAsync(() => input.Instance.OnChange.InvokeAsync(new InputFileCha
Assert.DoesNotContain("test5.png;test6.png", cut.Markup);
}


[Fact]
public void InputUpload_IsMultiple()
{
Expand Down
Loading