You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add bind function to simulate @Bind directive (#750)
* feat: Add bind function to simulate @Bind directive
* add: Documentation and samples
* added null checks and tests
* Apply suggestions from code review
Co-authored-by: Egil Hansen <egil@assimilated.dk>
* Better explanation if Bind encounters an error
* Added Tests
* tweaks to error messages
* Only replace last instance instead of every
* Apply suggestions from code review
Co-authored-by: Egil Hansen <egil@assimilated.dk>
* added e2e test
* wip - compare bind with Bind
* Added small example for bind in CHANGELOG.md
* improved bind compare test
* Update CHANGELOG.md
* fix changelog
Co-authored-by: Egil Hansen <egil@assimilated.dk>
The example renders the `<HelloWorld>` component inside the `<Wrapper>` component. What is special in both cases is the use of the `FindComponent<HelloWorld>()` that returns a `IRenderedComponent<HelloWorld>`. This is needed because the `RenderComponent<Wrapper>` method call returns an `IRenderedComponent<Wrapper>` instance, that provides access to the instance of the `<Wrapper>` component, but not the `<HelloWorld>`-component instance.
The example passes a inline Razor template to the `Render<TComponent>()` method. What is different here from the previous examples is that we use the generic version of the `Render<TComponent>` method, which is a shorthand for `Render(...).FindComponent<TComponent>()`.
387
387
388
388
***
389
389
390
+
## Configure two-way with component parameters (`@bind` directive)
391
+
392
+
To set up [two-way binding to a pair of component parameters](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/data-binding#binding-with-component-parameters) on a component under test, e.g. the `Value` and `ValueChanged` parameter pair on the component below, do the following:
The example uses the `Bind` method to setup two-way binding between the `Value` parameter and `ValueChanged` parameter, and the local variable in the test method (`currentValue`). The `Bind` method is a shorthand for calling the the `Add` method for the `Value` parameter and `ValueChanged` parameter individually.
The example uses the standard `@bind-Value` directive in Blazor to set up two way binding between the `Value` parameter and `ValueChanged` parameter and the local variable in the test method (`currentValue`).
0 commit comments