MatSelectValue breaks when you remove the last Item
DennGoss opened this issue · comments
DennGoss commented
Describe the bug
When you are removing the last item in a MatSelectValue it will break.
To Reproduce
Steps to reproduce the behavior:
- Create MatSelectValue with a binding 'Items' to a list.
- Remove last item in the list with a 'ButtonClickEvent'.
- Try to change selected item.
TestCode
@using MatBlazor
<MatSelectValue Label="Test:" @bind-Value="selectedTest" Items="@testList" ValueSelector="@(u => u)">
<ItemTemplate>
<span>@context?.Name</span>
</ItemTemplate>
</MatSelectValue>
<MatButton Style="color:red;" OnClick="BtnClickDelete"><i>Delete</i></MatButton>
@code {
public List<test> testList = new List<test>();
public test selectedTest = new test();
protected override void OnInitialized()
{
testList = new List<test> { new test() { Name = "A" }, new test() { Name = "B" }, new test() { Name = "C" } };
base.OnInitialized();
}
protected void BtnClickDelete(MouseEventArgs e)
{
testList.RemoveAt(testList.Count() - 1);
}
public class test{
public string Name;
}
}
Christian Oleson commented
@DennGoss ,
What error do you get?
DennGoss commented
@DennGoss ,
What error do you get?
You only get the error when you try to select another item.
matBlazor.js:1 Uncaught TypeError: Cannot read property 'focus' of undefined
at Object.focusMenuItemAtIndex (matBlazor.js:1)
at e.handleMenuOpened (matBlazor.js:1)
at HTMLDivElement.handleMenuOpened (matBlazor.js:1)
at e.t.emit (matBlazor.js:1)
at Object.notifyOpen (matBlazor.js:1)
at matBlazor.js:1