Cannot focus on custom textbox filter on multiselect dropdown

Hi,

I have added a multiselect dropdown with Mode="@VisualMode.Box" ​and I am trying to add a textbox in the header template so I can do the filtering on it without using the default filtering on the box itself. But it won't allow me to type on it because the focus is fixated on the multiselect selected items box. How can I focus on the custom textbox instead?


Thank you. 


5 Replies

SP Sureshkumar P Syncfusion Team February 9, 2022 02:12 PM UTC

Hi Harryi, 

We will validate the requirement in our component. We will update you in two business days (February 11th, 2022).  

Regards, 
Sureshkumar P 



SP Sureshkumar P Syncfusion Team February 11, 2022 12:23 PM UTC

Harryi, 
 
After render the custom textbox inside the multiselect popup element using header template we can move the focus to the textbox using JSIntrop method and restrict the popup close event by private boolean variable. As like below code. 
 
Find the code changes: 
@inject IJSRuntime JS 
 
<SfMultiSelect TValue="string[]" TItem="Countries" Placeholder="e.g. Australia" DataSource="@Country"> 
    <MultiSelectFieldSettings Text="Name" Value="Code"></MultiSelectFieldSettings> 
    <MultiSelectEvents TValue="string[]" TItem="Countries" Opened="OpenEvent" OnClose="PopupClose"></MultiSelectEvents> 
    <MultiSelectTemplates TItem="Countries"> 
        <HeaderTemplate> 
            <div> 
                <input id="customInput" @onfocusin="CuastomInputFocus"/> 
                @*<InputText id="customInput" @onfocusin="@CuastomInputFocus" @bind-Value="TextIbnput"></InputText>                *@ 
            </div> 
        </HeaderTemplate> 
    </MultiSelectTemplates> 
</SfMultiSelect> 
 
@code { 
    public string TextIbnput { get;set; } 
    public Boolean isFocus { get; set; } = false; 
 
    void CuastomInputFocus() 
    { 
        isFocus = true; 
    } 
 
    void PopupClose(PopupEventArgs args) 
    { 
        if (isFocus) 
        { 
            args.Cancel = true; 
            isFocus = false; 
        } else 
        { 
            args.Cancel = false; 
        } 
    } 
 
    protected async Task OpenEvent(Syncfusion.Blazor.DropDowns.PopupEventArgs args) 
    { 
        await JS.InvokeAsync<string>("Focus", "customInput"); 
    } 
 
    public class Countries 
    { 
        public string Name { get; set; } 
 
        public string Code { get; set; } 
    } 
 
    List<Countries> Country = new List<Countries> 
    { 
        new Countries() { Name = "Australia", Code = "AU" }, 
        new Countries() { Name = "Bermuda", Code = "BM" }, 
        new Countries() { Name = "Canada", Code = "CA" }, 
        new Countries() { Name = "Cameroon", Code = "CM" }, 
        new Countries() { Name = "Denmark", Code = "DK" } 
    }; 
} 
 
[Focus.js] 
function Focus(id) { 
    setTimeout(() => { 
        document.getElementById("customInput").focus(); 
    }, 500); 
} 
 
 
Regards, 
Sureshkumar P 



HA Harryi February 16, 2022 12:09 PM UTC

Hi Suresh,


Thank you for your example. This is exactly what I was after. However, when I have implemented your solution in my project the pop up exists on the first click on the multiselect box. I need to click twice to start typing on the filter textbox. Also, when I need to close the popup I need to click twice outside of the control as well. I have made a small capture (click) so it will explain better. What do you think causing this? I need to mention this issue does not happen in your example. Only in my project.

Than





HA Harryi February 17, 2022 09:11 AM UTC

Hi Suresh,


All good mate, I have figured it out. Thanks a lot for your help. Cheers!



SP Sureshkumar P Syncfusion Team February 17, 2022 01:10 PM UTC

Harryi, 
 
Thanks for your update. 
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon