-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
MatChipSet: set_SelectedChips cannot be used to preselect chips #671
Labels
bug
Something isn't working
Comments
This was referenced Aug 4, 2020
petert1401
pushed a commit
to petert1401/MatBlazor
that referenced
this issue
Aug 4, 2020
…t MatChip hash.
It is possible to solve this with using @ref on the MatChip and storing it in an array or something like it. Example: Markup <MatChipSet Filter="true" @bind-SelectedChips="selectedChips">
<MatChip Label="Wedges" IsCheckable="true" @ref="allChips[0]"/>
<MatChip Label="Circles" IsCheckable="true" @ref="allChips[1]"/>
<MatChip Label="Squares" IsCheckable="true" @ref="allChips[2]"/>
</MatChipSet> Code private MatChip[] allChips = new MatChip[3];
private MatChip[] selectedChips;
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
selectedChips = allChips.Where(x => x.Label == "Wedges").ToArray();
} It would still be nice with an easier way to do this, but maybe a parameter to access |
petert1401
pushed a commit
to petert1401/MatBlazor
that referenced
this issue
Oct 14, 2020
…t MatChip hash.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using MatChipSet.SelectedChips to preselect displayed chips in OnAfterRender, the comparison is done on a Hash of the MatChip, so a match will never be found.
As a result, chips cannot be preselected. Suggested fix below...
Reproduction Steps
Use the code in the sample/demo application on the 'Chip' page.
In the 'Filter ChipSet' section, replace the line
MatChip[] selectedChips = null;
with
MatChip[] selectedChips = new MatChip[] { new MatChip() { Label = "Wedges" } };
In the Razor file, add a ref value to the MatChipSet:-
Override the OnAfterRender method to set the selected chips:-
Expected Result
The 'Wedges' chip should be selected when the page is shown.
Actual Result
All chips are deselected.
Suggested Fix
In MatChipSet.cs, at line 75, match on the Label value, not a hash of the MatChip object:-
Replace
With
I'd have submitted a pull request, but I'm not a registered contributor...
The text was updated successfully, but these errors were encountered: