Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
if (ShowCloseButton)
{
<div class="multi-select-item-group">
<DynamicElement TagName="span" class="multi-select-close"
<DynamicElement TagName="span" class="multi-select-close" data-bb-val="@GetValueString(item)"
TriggerClick="@(!IsPopover)" OnClick="() => ToggleRow(item)">
<i class="@CloseButtonIcon"></i>
</DynamicElement>
Expand Down Expand Up @@ -127,7 +127,7 @@

@code {
RenderFragment<SelectedItem<TValue>> RenderRow => item =>
@<DynamicElement OnClick="() => ToggleRow(item)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)">
@<DynamicElement OnClick="() => ToggleItem(item)" TriggerClick="@CheckCanTrigger(item)" class="@GetItemClassString(item)">
<div class="multi-select-item">
<div class="form-check">
<input class="form-check-input" type="checkbox" disabled="@CheckCanSelect(item)" checked="@GetCheckedString(item)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public async Task ConfirmSelectedItem(int index)
var rows = Rows;
if (index < rows.Count)
{
await ToggleRow(rows[index]);
await ToggleItem(rows[index]);
StateHasChanged();
}
}
Expand All @@ -395,28 +395,45 @@ public async Task ConfirmSelectedItem(int index)
/// </summary>
/// <returns></returns>
[JSInvokable]
public async Task ToggleRow(SelectedItem<TValue> val)
public async Task ToggleRow(string val)
{
if (!IsDisabled)
if (int.TryParse(val, out var index) && index >= 0 && index < SelectedItems.Count)
{
var item = SelectedItems.FirstOrDefault(i => Equals(i.Value, val.Value));
if (item != null)
{
SelectedItems.Remove(item);
}
else
var item = SelectedItems[index];
await ToggleRow(item);
}
}

private async Task ToggleRow(SelectedItem<TValue> item)
Comment on lines +403 to +407
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates infinite recursion. The method ToggleRow(string val) calls ToggleRow(item) which should be calling the private ToggleRow(SelectedItem<TValue> item) method instead.

Suggested change
await ToggleRow(item);
}
}
private async Task ToggleRow(SelectedItem<TValue> item)
await ToggleRowInternal(item);
}
}
private async Task ToggleRowInternal(SelectedItem<TValue> item)

Copilot uses AI. Check for mistakes.
{
SelectedItems.Remove(item);

_isToggle = true;
// 更新选中值
await SetValue();
}
Comment on lines +407 to +414
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method only removes items and doesn't check the IsDisabled state, unlike the original ToggleRow implementation. Consider adding the disabled check for consistency.

Copilot uses AI. Check for mistakes.

private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider handling case where item is not in SelectedItems.

IndexOf returns -1 if the item is not found, which may not be appropriate for GetValueString. Consider returning null or a different sentinel value instead.

Suggested change
private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null;
private string? GetValueString(SelectedItem<TValue> item)
{
if (!IsPopover)
{
return null;
}
var index = SelectedItems.IndexOf(item);
return index >= 0 ? index.ToString() : null;
}


private async Task ToggleItem(SelectedItem<TValue> val)
{
var item = SelectedItems.FirstOrDefault(i => Equals(i.Value, val.Value));
if (item != null)
{
SelectedItems.Remove(item);
}
else
{
var d = Rows.FirstOrDefault(i => Equals(i.Value, val.Value));
if (d != null)
{
var d = Rows.FirstOrDefault(i => Equals(i.Value, val.Value));
if (d != null)
{
SelectedItems.Add(d);
}
SelectedItems.Add(d);
}

_isToggle = true;
// 更新选中值
await SetValue();
}

_isToggle = true;
// 更新选中值
await SetValue();
}

private int _min;
Expand Down
Loading