diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs index a60c48ab2a..f21c5e3b8f 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/Dropdown/BitDropdown.razor.cs @@ -126,6 +126,11 @@ namespace Bit.BlazorUI; /// [Parameter] public RenderFragment? HeaderTemplate { get; set; } + /// + /// The initial items that will be used to set selected items when using an ItemProvider. + /// + [Parameter] public IEnumerable? InitialSelectedItems { get; set; } + /// /// Determines the opening state of the callout. (two-way bound) /// @@ -779,14 +784,32 @@ protected override async Task OnInitializedAsync() if (MultiSelect) { - if (ValuesHasBeenSet is false && DefaultValues is not null) + if (ItemsProvider is not null && (InitialSelectedItems?.Any() ?? false)) + { + _selectedItems.AddRange(InitialSelectedItems); + + if (ValuesHasBeenSet is false) + { + await AssignValues(_selectedItems.Select(s => GetValue(s))); + } + } + else if (ValuesHasBeenSet is false && DefaultValues is not null) { await AssignValues(DefaultValues); } } else { - if (ValueHasBeenSet is false && DefaultValue is not null) + if (ItemsProvider is not null && (InitialSelectedItems?.Any() ?? false)) + { + _selectedItems.Add(InitialSelectedItems.First()); + + if (ValueHasBeenSet is false) + { + Value = GetValue(_selectedItems.First()); + } + } + else if (ValueHasBeenSet is false && DefaultValue is not null) { Value = DefaultValue; } @@ -1143,6 +1166,9 @@ private async ValueTask> InternalItemsProvider(ItemsP _lastShowItems = [.. providerResult.Items]; + UpdateSelectedItemsFromValues(); + await InvokeAsync(StateHasChanged); + return new ItemsProviderResult(providerResult.Items, providerResult.TotalItemCount); } diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cs index 96cacf31fa..1fcc769595 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Inputs/Dropdown/BitDropdownDemo.razor.cs @@ -131,6 +131,13 @@ public partial class BitDropdownDemo Description = "The custom template for rendering the header items of the dropdown.", }, new() + { + Name = "InitialSelectedItems", + Type = "IEnumerable?", + DefaultValue = "null", + Description = "The initial items that will be used to set selected items when using an ItemProvider.", + }, + new() { Name = "IsOpen", Type = "bool",