Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ protected async Task CheckFocus(int count)
return;
}
string str = ConvertSet(_theValue.Value) ?? string.Empty;
await _elementReferences[str.Length].FocusAsync();
await _elementReferences[Math.Min(str.Length, _count.Value - 1)].FocusAsync();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Bunit;
using AwesomeAssertions;
using Microsoft.AspNetCore.Components;

namespace MudExtensions.UnitTests.Components
{
[TestFixture]
public class CodeInputTests : BunitTest
{
[TestCase("123", 3)]
[TestCase("123456", 5)]
public async Task CodeInput_Focus_RedirectsToFirstEmptyOrLastBox(string value, int expectedIndex)
{
var comp = Context.Render<MudCodeInput<string>>(opt =>
{
opt.Add(a => a.Count, 6);
opt.Add(a => a.Value, value);
});
var fields = comp.FindComponents<MudTextFieldExtended<string>>();

await comp.FindAll("input")[1].FocusAsync(new());

var focused = (ElementReference)Context.JSInterop.VerifyFocusAsyncInvoke().Arguments[0]!;
focused.Id.Should().Be(fields[expectedIndex].Instance.InputReference.ElementReference.Id);
}
}
}
Loading