Skip to content

Commit

Permalink
merge results
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Dec 4, 2024
2 parents 48b6d83 + a4863be commit 1f9b44e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ namespace Bit.BlazorUI;
/// </summary>
[Parameter] public RenderFragment<TItem>? HeaderTemplate { get; set; }

/// <summary>
/// The initial items that will be used to set selected items when using an ItemProvider.
/// </summary>
[Parameter] public IEnumerable<TItem>? InitialSelectedItems { get; set; }

/// <summary>
/// Determines the opening state of the callout. (two-way bound)
/// </summary>
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1143,6 +1166,9 @@ private async ValueTask<ItemsProviderResult<TItem>> InternalItemsProvider(ItemsP

_lastShowItems = [.. providerResult.Items];

UpdateSelectedItemsFromValues();
await InvokeAsync(StateHasChanged);

return new ItemsProviderResult<TItem>(providerResult.Items, providerResult.TotalItemCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TItem>?",
DefaultValue = "null",
Description = "The initial items that will be used to set selected items when using an ItemProvider.",
},
new()
{
Name = "IsOpen",
Type = "bool",
Expand Down

0 comments on commit 1f9b44e

Please sign in to comment.