-
-
Notifications
You must be signed in to change notification settings - Fork 362
fix(MultiSelectGeneric): close button not work #6754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| SelectedItems.Remove(item); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| _isToggle = true; | ||||||||||||||||||||||
| // 更新选中值 | ||||||||||||||||||||||
| await SetValue(); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+407
to
+414
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private string? GetValueString(SelectedItem<TValue> item) => IsPopover ? SelectedItems.IndexOf(item).ToString() : null; | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
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)callsToggleRow(item)which should be calling the privateToggleRow(SelectedItem<TValue> item)method instead.