DavidVollmers / Ignis

The Blazor framework for building modern web applications.
https://ignis.dvolper.dev
MIT License
150 stars 8 forks source link

ListBox value cannot be nullable anymore #46

Closed nullreferencez closed 8 months ago

nullreferencez commented 8 months ago

Listbox previously was able to handle be bound to a nullable property however with the new update it throws an exception.

<Listbox Context="paymenType" @bind-Value="_createPayment.SelectedPaymentType">

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object. at Ignis.Components.HeadlessUI.ListboxOption1[[Shared.PaymentType, Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<.ctor>b__24_0() at Ignis.Components.AttributeCollection.GetEnumerator()+MoveNext() at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddMultipleAttributes(Int32 sequence, IEnumerable1 attributes) at Ignis.Components.HeadlessUI.ListboxOption`1[[Shared.PaymentType, Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].BuildRenderTree(RenderTreeBuilder builder) at Ignis.Components.IgnisComponentBase.<.ctor>b__10_0(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

works fine on 0.13.1

DavidVollmers commented 8 months ago

Thank you for creating the issue, I will have a look as soon as possible!

nullreferencez commented 8 months ago

Just to give you a little but more clarification, SelectedPaymentType would be a nullable Enum property. Now it works on the Listbox but in the ListboxOption it will throw an error. This worked fine prior and still works if i make the property not nullable and set a default value.

                    <Listbox Context="interval" @bind-Value="_createPayment.SelectedPaymentType">
                        <div class="relative mt-1">
                            <ListboxButton class="relative w-full ring-1 ring-inset ring-gray-300 rounded-lg bg-white py-1 pl-3 pr-10 text-left focus:outline-none focus-visible:border-emerald-600 focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75 focus-visible:ring-offset-2 focus-visible:ring-offset-emerald-600 sm:text-sm">
                                <span class="block truncate">
                                    @if (_createPayment.SelectedPaymentType is null)
                                    {
                                        <span>Select a payment type</span>
                                    }
                                    else
                                    {
                                        <div class="flex p-2">
                                            <CreditCardIcon class="h-5 w-5 text-emerald-600 mr-2" />
                                            <p class="text-gray-900">@_createPayment.SelectedPaymentType</p>
                                        </div>
                                    }
                                </span>
                                <span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
                                    <ChevronUpDownIcon class="h-5 w-5 text-gray-400" />
                                </span>
                            </ListboxButton>
DavidVollmers commented 8 months ago

Hi, so I am struggling to reproduce this. Can you please extend the above example with the ListboxOption code?

DavidVollmers commented 8 months ago

I will close this issue for now since I cannot reproduce it with the given details. Feel free to comment with more details if the issue still persists.

dosimetrybadge commented 8 months ago

Sorry i was very busy. I will produce you some code over the weekend that showcases the issue.