MatList - Impossible to clear the selection
Hello,
I'm trying to clear the selection on a MatList.
I proceed this way :
matList.SetSelectedIndex(-1);
This doesn't work, but when I try to use SetSelectedIndex() for an existing element all goes fine.
Am I doing something wrong ? I also tried to set it at int.MaxValue but this doesn't work.
Do you have an idea ?
It doesn't work because MatBlazor only forwards "SetSelectedIndex(-1)" to the SetSelectedIndex() defined in material components. This function in material components does nothing if the input index is not within range. See https://github.com/material-components/material-components-web/tree/master/packages/mdc-list
I will tag this issue as an enhancement since i definitely see the need for such a method on MatList in MatBlazor (I know the list in Angular Material has it)
Thanks for the feedback
Hi @lindespang
I am new in Blazor, we just started to use it for one project in work and i also need to clear a selection in the list. If i understand it correctly, this problem was caused by implementation of isIndexValid_ function in the foundation.ts and it was resolved 10 months ago here in this commit- https://github.com/material-components/material-components-web/blame/ab99b8064a9b3cc1311c43245b3f5a0b84ef965d/packages/mdc-list/foundation.ts#L621- line 621 in the foundation.ts. Can i expect that those changes will be part of MatBlazor soon?
Eventually - exists any workaround to clear a selection in list? Thanks.