CodeBeamOrg / CodeBeam.MudBlazor.Extensions

Useful third party extension components for MudBlazor, from the contributors.
https://mudextensions.codebeam.org/
MIT License
371 stars 62 forks source link

MudSelectExtended chipsets not closeable for complex type #163

Closed MilesFan closed 1 year ago

MilesFan commented 1 year ago

I have problems getting MudSelectExtended working with closeable chips + complex type.

On TryMudextensions the close button of chips is not responsive. While with the exact same code on my machine, the chips are not even displayed unless clicking on the input.

What am I doing wrong? Please help!

<MudAlert Severity="Severity.Info" Class="mt-4">
    The following example demostrates chips are not closeable. <br />
    On my machine, chips are not even displayed unless the input is focused.
</MudAlert>

<MudSelectExtended @bind-SelectedValues="animalsSelected" T="Animal" ItemCollection="animals"
                   MultiSelection="true" Label="Animals" SearchBox="true"
                   ChipCloseable="true" ValuePresenter="MudExtensions.Enums.ValuePresenter.Chip"
                   AnchorOrigin="Origin.BottomCenter" />

@code {
    class Animal
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public override string ToString() => this.Name;
        public override int GetHashCode() => this.Id.GetHashCode();
        public override bool Equals(object? that) => (that as Animal)?.Id == this.Id;
    }

    private ICollection<Animal> animals = new List<Animal> {
        new Animal { Id = Guid.NewGuid(), Name = "Dog" },
        new Animal { Id = Guid.NewGuid(), Name = "Cat" },
        new Animal { Id = Guid.NewGuid(), Name = "Bear" },
        new Animal { Id = Guid.NewGuid(), Name = "Lion" },
        new Animal { Id = Guid.NewGuid(), Name = "Horse" },
        new Animal { Id = Guid.NewGuid(), Name = "Donkey" },
        new Animal { Id = Guid.NewGuid(), Name = "Sheep" },
    };

    private IEnumerable<Animal> animalsSelected = new List<Animal>();

    protected override void OnInitialized()
    {
        //for demostration, the first 3 items are selected by default
        animalsSelected = animals.Take(3);

        base.OnInitialized();
    }
}
mckaragoz commented 1 year ago

Which version do you use?

MilesFan commented 1 year ago

Which version do you use?

I am using CodeBeam.MudBlazor.Extensions 6.4.5.

MudBlazor is 6.1.9, Blazor WASM, Net 7, just in case the information would be helpful. :)

mckaragoz commented 1 year ago

It's surely a bug, i updated try MudExtensions also 6.4.5.

For now you can use renderfragment approach instead of ItemCollection. It even can't close the chips with click but at least show them properly.

<MudSelectExtended @bind-SelectedValue="animal" @bind-SelectedValues="animalsSelected" T="Animal"
                   MultiSelection="true" Label="Animals" SearchBox="false"
                   ChipCloseable="true" ValuePresenter="MudExtensions.Enums.ValuePresenter.Chip"
                   AnchorOrigin="Origin.BottomCenter">
    @foreach (var item in animals)
    {
        <MudSelectItemExtended Value="@item" Text="@item.Name" />
    }
</MudSelectExtended>
MilesFan commented 1 year ago

Thanks for the feedback. At least I don't doubt myself any more. Hope it will be fixed in the next release. :)

Awesome project, by the way.

mckaragoz commented 1 year ago

https://user-images.githubusercontent.com/78308169/228045823-7aee767b-9410-4db9-acd4-43fc2f36c4ff.mp4

Now it look like working with both RenderFragment and ItemCollection approach. They both visible initially and can close with complex objects. Will come with next release, but i should say its not final shape of MudSelectExtended, extended one fixes lots of issues, but probably we will wait net 8 for a zero-problem select.