What is Attribute Splatting and CaptureUnmatchedValues, and why are they useful for wrapper components?
Last updated
A
[Parameter(CaptureUnmatchedValues = true)]property of typeDictionary<string, object>collects any attributes the caller passes that don't match a declared parameter.Attribute splatting applies that dictionary to a rendered element with
@attributes.Wrapper components (e.g. a custom input) can then accept
class,placeholder,aria-*and more without declaring each, behaving like native elements.
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/splat-attributes-and-arbitrary-parameters?view=aspnetcore-10.0
- https://www.meziantou.net/capturing-unmatched-attributes-and-attribute-splatting-in-blazor.htm
- https://learn.microsoft.com/en-us/aspnet/core/blazor/performance/rendering?view=aspnetcore-10.0
- https://blazor-university.com/components/capturing-unexpected-parameters/
- https://medium.com/dotnet-new/advanced-blazor-component-techniques-for-clean-scalable-ui-development-7e8f03dd3e89
- https://www.pragimtech.com/blog/blazor/blazor-attribute-splatting/
- https://www.binaryintellect.net/articles/f02cee62-3e2f-40a6-bdf1-e642ba7f23ce.aspx