tweetysat
tweetysat

Reputation: 2403

Angular 6 - Matierial Radio Button & Material Input

I'm working on something like

https://stackblitz.com/edit/angular-tayp2o

What I'm trying to do is :

The second goal is not working. The focus is well given but lost immediately. But clicking on the test button is working.

How can I do ?

Upvotes: 1

Views: 51

Answers (1)

jsadev.net
jsadev.net

Reputation: 2590

The Problem is that you're trying to set the focus to an element by clicking on an other element. But HTML is setting the focus to the clicked element by default.

To solve this issue you could use a timeout inside your 'radioFocus' function:

radioFocus(event: any) {
  setTimeout(() => { document.getElementsByName(event.srcElement.id).item(0).focus(); }, 100);
}

Upvotes: 2

Related Questions