How can I make a combobox open or close by clicking anywhere on the control.

1 Answer 1925 Views
ComboBox
Marvin
Top achievements
Rank 1
Iron
Iron
Marvin asked on 24 Feb 2022, 02:16 PM

I would like my comboboxes to open or close the way a DropDownList works by clicking anywhere on the control, not just the arrow button.

 

I have tried handling the click event and calling .toggle(), but if I do this then clicking on the arrow button does not work.

1 Answer, 1 is accepted

Sort by
0
Martin Bechev
Telerik team
answered on 01 Mar 2022, 07:40 AM

Hi Marvin,

Using the toggle method is the right way to go when the ComboBox items need to be toggled programmatically. 

Instead of handling the generic click event, try using the focus event and see if the component is being opened already, by checking the isOpen field:

 <kendo-combobox #combo [data]="listItems" (focus)="onFocus(combo)">
 </kendo-combobox>
public onFocus(combo) {
    if (!combo.isOpen) {
      combo.toggle(true);
    }
  }

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Marvin
Top achievements
Rank 1
Iron
Iron
commented on 01 Mar 2022, 01:56 PM

Thank you Martin.  Your solution works pretty good when clicking to initially focus the combo box.  It doesn't handle subsequent clicks like a DropDownList does however. 

So far the best code that is working for me is this, which tests the class names on the clicked target to see if the arrow was clicked.

<kendo-combobox #cb [data]="listItems" (click)="!$event.target.className.includes('k-select') && !$event.target.parentElement.className.includes('k-select') && cb.toggle()"

></kendo-combobox>


 

Tags
ComboBox
Asked by
Marvin
Top achievements
Rank 1
Iron
Iron
Answers by
Martin Bechev
Telerik team
Share this question
or