Combobox autoFocus={true} not working.

1 Answer 516 Views
ComboBox
Karthikeyan
Top achievements
Rank 1
Iron
Karthikeyan asked on 15 Jul 2021, 07:53 AM | edited on 15 Jul 2021, 07:54 AM

Hi Team,

 

I'm trying to auto Focus the combobox control but it is not working. 

<ComboBox id="xyz" autoFocus={true} />

1 Answer, 1 is accepted

Sort by
0
Krissy
Telerik team
answered on 15 Jul 2021, 09:13 AM

Hi Karthikeyan,

Auto-focusing the ComboBox can be achieved by using the JavaScript focus method to focus the ComboBox element when the component has rendered:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus

I've created an example to showcase how to achieve this by finding the ComboBox element based on its id using the document.getElementById method and the JS focus method to focus it:
https://stackblitz.com/edit/react-4cesgj?file=app/main.jsx 

Hope this helps.

Regards,
Krissy
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Karthikeyan
Top achievements
Rank 1
Iron
commented on 15 Jul 2021, 09:38 AM

I'm using Class based Component. Do you have any sample application like you shared
Karthikeyan
Top achievements
Rank 1
Iron
commented on 15 Jul 2021, 09:53 AM

Hi Team, ThankYou, I add the same code in componentDidMount() it got worked. Thanks
Krissy
Telerik team
commented on 15 Jul 2021, 09:54 AM

Hi Karthikeyan,

Here is an example of the same case using a class based component and the componentDidMount method: 
https://stackblitz.com/edit/react-4cesgj-rv2eoo?file=app/main.jsx 

Hope this is what you are looking for.
Tags
ComboBox
Asked by
Karthikeyan
Top achievements
Rank 1
Iron
Answers by
Krissy
Telerik team
Share this question
or