From c18079545c89f0cac8aa3436a56292c5c4c30fde Mon Sep 17 00:00:00 2001 From: Roland <195342210+rpodevns@users.noreply.github.com> Date: Sat, 18 Jan 2025 14:16:20 +0000 Subject: [PATCH] [FluentInputFile] Add OnFileCountExceeded callback (#3205) Co-authored-by: rpodevns --- .../Microsoft.FluentUI.AspNetCore.Components.xml | 6 ++++++ .../Components/InputFile/FluentInputFile.razor.cs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml index fd33e4bec..4b0582b34 100644 --- a/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml +++ b/examples/Demo/Shared/Microsoft.FluentUI.AspNetCore.Components.xml @@ -5145,6 +5145,12 @@ Raise when a file raised an error. Not yet used. + + + Raised when the is exceeded. + The return parameter specifies the total number of files that were attempted for upload. + + Raise when all files are completely uploaded. diff --git a/src/Core/Components/InputFile/FluentInputFile.razor.cs b/src/Core/Components/InputFile/FluentInputFile.razor.cs index 43a874455..293d58651 100644 --- a/src/Core/Components/InputFile/FluentInputFile.razor.cs +++ b/src/Core/Components/InputFile/FluentInputFile.razor.cs @@ -146,6 +146,13 @@ public FluentInputFile() [Parameter] public EventCallback OnFileError { get; set; } + /// + /// Raised when the is exceeded. + /// The return parameter specifies the total number of files that were attempted for upload. + /// + [Parameter] + public EventCallback OnFileCountExceeded { get; set; } + /// /// Raise when all files are completely uploaded. /// @@ -215,7 +222,11 @@ protected async Task OnUploadFilesHandlerAsync(InputFileChangeEventArgs e) { if (e.FileCount > MaximumFileCount) { - throw new ApplicationException($"The maximum number of files accepted is {MaximumFileCount}, but {e.FileCount} were supplied."); + if (OnFileCountExceeded.HasDelegate) + { + await OnFileCountExceeded.InvokeAsync(e.FileCount); + } + return; } // Use the native Blazor event