MBSegmentedButtonMulti<TItem>
Summary
A Material Segmented Button as a multi-select.
Details
- Accepts an
IEnumerable<MBIconBearingSelectElement<TItem>>of selectable items; - Binds to an
IList<TItem>of all items selected; - Ignores the
Disabledparameter because Material Components Web segmented buttons do not implement a disabled state.
Assisting Blazor Rendering with @key
- MBSegmentedButtonMulti renders similar buttons with a
foreachloop; - In general each item rendered in a loop in Blazor should be supplied with a unique object via the
@keyattribute - see Blazor University; - MBSegmentedButtonMulti by default uses the
SelectedValueproperty of each item in theItemsparameter as the key, however you can override this. Material.Blazor does this because we have had instances where Blazor crashes with the default key giving an exception message such as "The given key 'MyObject' was not present"; - You can provide a function delegate to the
GetKeysFuncparameter - we have used two variants of this:- First to get a unique
Idproperty that happens to be in our item's class:GetKeysFunc="@((item) => item.Id)"; and - Second using a "fake key" where we create a GUID to act as the key:
GetKeysFunc="@((item) => Guid.NewGuid())". - You can see an example of this in the MBList demonstration website page's code.
- First to get a unique