I would like to have a React ComboBox select the text when the onFocus Event is fired

1 Answer 49 Views
ComboBox
Jimmy
Top achievements
Rank 1
Iron
Jimmy asked on 22 Mar 2022, 07:33 PM

I am trying to highlight the text in a combobox so that I can highlight the text when a user clicks in the combo box.

 

Here is a sample of what I am trying to do:

  <ComboBox
                            className='k-combobox'
                            placeholder='Select Center'
                            data={this.state.centerAccessFiltered }
                            textField="centerDisplayName"
                            value={this.state.selectedCenter}
                            filterable={true}
                            onFilterChange={this.filterChange}
                            onChange={(e) => this.changeCenter(e.target.value.centerID.toString())}
                            clearButton={false}
                            onFocus={this.handleFocus}
                        />

 

    handleFocus = (e) => {
        e.target.element.select()
    }

 

 

This works on the Input Control but not on the ComboBox.  Is there a way to select the current text when as user clicks on the control?

 

 

1 Answer, 1 is accepted

Sort by
1
Konstantin Dikov
Telerik team
answered on 24 Mar 2022, 07:52 AM

Hi Jimmy,

The ComboBox element is the wrapping span element and not the input. In order to get reference to the input element and select the value you can use this instead:

handleFocus = (e) => {
    e.syntheticEvent.currentTarget.select();
  };

Here is an example with the above approach:

Hope this helps.

 

Regards,
Konstantin Dikov
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.

Jimmy
Top achievements
Rank 1
Iron
commented on 24 Mar 2022, 12:20 PM

That worked great!!!!  Thank you.  
Tags
ComboBox
Asked by
Jimmy
Top achievements
Rank 1
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or