Skip to content

MudCodeInput - MudInput.FocusAsync: ElementReference has not been configured correctly. #611

Closed

Description

@MarkHorton56

Blazor server side error reported MudInput.FocusAsync: ElementReference has not been configured correctly given the below configuration and all 6 fields completed; pressing tab or moving focus with cursor causes the error to repeat.

The code here needs check the length does not exceed the Count value.

Suggest
int focusIndex = Math.Min(Count-1, str.Length);

<MudCodeInput Class="login"
                              InputType="InputType.Number"
                              T="string"
                              @bind-Value="@_inputCode"
                              Count="6"
                              Spacing="2"
                              Variant="Variant.Outlined"
                              Margin="Margin.None"
                              Required="true"/>

Activity

  1. nurullahturkoglu commented on Oct 10, 2026

    @nurullahturkoglu
    Contributor

    Hi @mckaragoz, I can reproduce this on dev. When every box is filled, CheckFocus focuses _elementReferences[str.Length], which is one of the placeholder instances created in SyncReferences() and never rendered. MudInputExtended.FocusAsync catches the failure and logs it, so the app doesn't crash, but focus stays on the clicked box and the error is logged on every focus.

    I'd like to fix this and add a bUnit test for MudCodeInput (it has none yet). Which behavior would you prefer when all boxes are filled?

    1. Focus the last box, as suggested above.
    2. Don't redirect at all and leave focus on the box that was clicked.
  2. mckaragoz commented on Oct 10, 2026

    @mckaragoz
    Contributor
    1. Focus the last box, as suggested above.

    This would be better. Thanks for handling the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions