mardi 21 juillet 2020

Creating a Tri-State checkbox component for blazor

<input @bind="Checked" type="checkbox" @onclick="eventArgs => { onclick(); }" indeterminate="@indeterminate" class="checkbox-input">

@code {
    [Parameter]
    public bool? selected { get; set; } = null;

    public bool indeterminate { get; set; }

    public bool Checked { get; set; }

    public void onclick()
    {



        selected = selected == null ? true : selected == true ? new bool?() : false;



        Checked = selected == null || selected == false;
        indeterminate = selected == null;

    }
}

This doesn't produce the desired result

The checkbox is always either checked or unchecked, never indeterminate.

Any ideas?




Aucun commentaire:

Enregistrer un commentaire