MatBlazor icon indicating copy to clipboard operation
MatBlazor copied to clipboard

MatSelectValue breaks when you remove the last Item

Open DennGoss opened this issue 4 years ago • 2 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 avatar Apr 13 '21 10:04 DennGoss

@DennGoss , What error do you get?

Christian-Oleson avatar May 05 '21 09:05 Christian-Oleson

@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

DennGoss avatar May 17 '21 08:05 DennGoss