Skip to content

When using StateHasChanged, the value is not reflected in the InputText #49069

@UdhayaKumarDuraisamy

Description

@UdhayaKumarDuraisamy

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In the InputText component, when using StateHasChanged, the value change is not reflected in the UI of the InputText component.

<div style="margin:130px auto;width:300px">
    <div class="form-group">
        <label for="inputText">InputText:</label>
        <InputText id="inputText" class="form-control" Value="@InputText" ValueExpression="@(() => InputText)" ValueChanged="HandleValueChanged" />
    </div>
    Current InputText: @InputText
</div>

@code {

    public string InputText { get; set; } = "abc";

    protected void HandleValueChanged(string? args)
    {
        if (args != "test")
        {
            InputText = args;
        }
        else
        {
            StateHasChanged();
        }
    }
}

Expected Behavior

Expected Output: When using StateHasChanged, the value needs to be reflected in the input of the InputText also.
Current Output: When using StateHasChanged, the value is not reflected in the input of the InputText .

Steps To Reproduce

  1. Run the Sample.
  2. Type “Example” and focus out.
  3. Now, The Values are updated properly in Both UI and ValueChanged event args.
  4. Type “test” and focus out.

Exceptions (if any)

No response

.NET Version

net7.0

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions