SamProf / MatBlazor

Material Design components for Blazor and Razor Components

Home Page:http://www.matblazor.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MatSelectValue breaks when you remove the last Item

DennGoss opened this issue · comments

Describe the bug
When you are removing the last item in a MatSelectValue it will break.

To Reproduce
Steps to reproduce the behavior:

  1. Create MatSelectValue with a binding 'Items' to a list.
  2. Remove last item in the list with a 'ButtonClickEvent'.
  3. 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;
    }
}

@DennGoss ,
What error do you get?

@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