Custom control that mimic a combobox winform in Blazor, question about item list and losing focus

26 Views Asked by At

I am beginner in Blazor so I am still experimenting in my demo application I have a class with some fields and one is just a text element. I want to make it react in a similar way as a combobox in winform, so I want a sort of autofilter of the items in source list and when I edit text the list open up and show me the items filtered and I want to be able to select item with keyboard and mouse click. So I made a custom control in Blazor adding an where user insert text and attached to the I add a list control where I show the result of a query based on the "like" of the text inserted by the user. Offcourse this control is not bound to the original class field but it is bound to a custom text field property and when user write or select an item in the list I have to assign the value to the original class field. I know it's ugly but at least is working, but what I not like of this solution is that if the user start to typing some text on the input field and list show up, if I click on another input on my form the list stay open forever or at least until the other control finish editing. I did try to intercept the onblur event of the but clearly when I click on the list item I lose the focus too so I losing my item selection too. At the moment the only solution I found and it's quite ugly is passing a parameter on the control (showlist) and every time I click on a control inside my form I set it to false so the control will not show the list items. If anyone have some suggestion about I would like to know what will be the better solution (apart use a third party control) best regards.

0

There are 0 best solutions below