Feature Request
The ability to specify whether or not the md-selection-list
supports multiple value selection. I see a few different implementation options:
multiple
attribute on md-selection-list
.checkbox
, otherwise render as radio
buttons.type
attribute on md-selection-list
.checkbox
(default) and radio
.md-list-option
components. ex md-list-radio-option
.md-selection-list
always renders each child md-list-option
as a checkbox.
MdSelectionList
is a good starting point for building generic Q&A style wizards/walkthroughs, but you are immediately limited in control over valid option selections. Having the ability to limit user selection to a single list option, presented using radio buttons, seems like it would be a reasonable extension of current behavior.
I don't understand, why this issue is labeled as "minor".
It's a commonly used building block and shouldn't be hard to implement.
I'd suggest a different implementation though: Multiple value selection by default and single selection on demand (via an attribute, e.g. single
). This would be a non-breaking change (contrary to the suggested multiple
attribute).
This is an important issue.
However, you can jack the selection handler of an element and just access the list to deselect the other items. You then jack the deselection handler to not allow something to be unselected.
As @Kyderman suggested, this would be the hacky way to achieve the radio-list behavior:
<mat-selection-list (selectionChange)="handleSelection($event)">
...
</mat-selection-list>
handleSelection(event) {
if (event.option.selected) {
event.source.deselectAll();
event.option._setSelected(true);
}
}
Thanks @gabriellupu , works perfectly fine.
Should be a standard included feature though... it's so basic and useful.
It looks the MDC-based list does support single selection. https://github.com/material-components/material-components-web/tree/master/packages/mdc-list#single-selection-list.
We could support that in our MDC-based implementation of the list. #16255
Most helpful comment
As @Kyderman suggested, this would be the hacky way to achieve the radio-list behavior: