logo

ComponentPropsProvider

When To Use

Use ComponentPropsProvider when a component renders child components internally and their source-generated XxxProps should be configured from outside, without exposing every child parameter on the parent component.

Override rules

  • Passing XxxProps to the ComponentPropsCollection constructor supplies default props to every child of the matching type.
  • [id] = props only overrides the child with the matching Id.
  • Props are merged in the order: outer provider, inner provider, then the id-specific entry. A later props object changes only the properties explicitly assigned to it.

One provider can contain multiple props types, while every XxxProps object remains strongly typed.

Examples

One ComponentPropsProvider can contain multiple props types. This example makes both buttons primary, enables quick jumping on both paginations, and enables the page-size changer only on the bottom pagination (Table<T>.BottomPaginationId).

expand code expand code

The global ButtonProps makes every button primary. ["delete"] and ["publish"] only change the Button with the matching Id. Local props override only their explicitly assigned properties, so the global Type is retained.

expand code expand code

Providers can be nested. An inner provider inherits the outer collection and overrides only the properties it explicitly sets. The inner buttons in this example are both Primary from the outer scope and Disabled from the inner scope.

expand code expand code

StatusCard is a custom component derived from AntComponentBase. The source generator creates StatusCardProps from its [Parameter] properties, so custom and built-in components use the same provider mechanism. The default description applies to both cards; the warning card then overrides its highlighted state and description by Id.

Note: Put the custom component's partial class declaration and [Parameter] properties in a .cs or .razor.cs file, not only in a .razor @code block. The current source generator reads C# syntax trees and cannot discover type declarations from Razor files.

expand code expand code
文档已更新,请点击 此处 更新。
A new version of this app is available. Click here to update.