How to autofocus the textbox when clicking on label?

1 Answer 72 Views
Accessibility Label NumericTextBox TextBox
Deepali
Top achievements
Rank 1
Deepali asked on 06 Jun 2022, 12:23 PM

Hello

I have a question. On click of a label, I want my kendo numeric textbox to have focus, but it is not working. Following is my code.

<label for="kid">Currency</label>

<kendo-numerictextbox
  [attr.id]="'kid'"
  [format]="formatOptions"
  [min]="min"
  [max]="max"
  [step]="step"
  [autoCorrect]="true"  
  [spinners]="false"
  [formControl]="control"
  [changeValueOnScroll]="false"
>
</kendo-numerictextbox>

Issue is because, at the run time kendo generates a random ID, and appends that ID to the input box(.k-input) , instead of appending the id given by the user as above. This is causing the issue and focus is not set on input box when clicking in label. Could you please check it and suggest a solution.

"@progress/kendo-angular-inputs": "^9.0.0",

 

Thank you

1 Answer, 1 is accepted

Sort by
0
Hetali
Telerik team
answered on 08 Jun 2022, 04:18 PM

Hello Deepali,

The Label can be associated to any HTML element using the id attribute. However, to associate any Kendo UI component with the Label, template reference variable is the way to go. Please find more details in this documentation page.

In order to focus on the Kendo UI NumericTextBox when the Label is clicked on, associate the for property of the Label to the template reference variable of the component. For example:

<label [for]="numerictextbox">NumericTextBox: </label>
<kendo-numerictextbox #numerictextbox>
</kendo-numerictextbox>

In this StackBlitz example, the NumericTextBox is focused when you click on the associated Label.

I hope this helps.

Regards,
Hetali
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/.

Deepali
Top achievements
Rank 1
commented on 15 Jul 2022, 07:33 AM

Thanks Hetali for you reply. But here the problem with me is my label is in one component and kendo-numerictextbox is coming from another component. In this case using template reference variable is not working.
Deepali
Top achievements
Rank 1
commented on 15 Jul 2022, 07:34 AM

I would suggest Kendo should also use id approach to set the focus instead of template ref variable.
Hetali
Telerik team
commented on 18 Jul 2022, 05:36 PM

Hi Deepali,

I understand your frustration. 

I did notice the Feature Request created by you and added a vote on your behalf. Please follow the request to receive future status updates pertaining to the same. Based on the votes, feasibilty, etc, the feature will be considered and added to our roadmap.

Please let me know if I can further assist you.

Regards,
Hetali
Progress Telerik
Tags
Accessibility Label NumericTextBox TextBox
Asked by
Deepali
Top achievements
Rank 1
Answers by
Hetali
Telerik team
Share this question
or