I finally got it to work using a lame workaround. I set the tabindex to -1 for the elements above the textarea. This makes the textarea the first tabbable element. This does the trick but I would still prefer to use ViewChild or a custom directive here. Cheers. Dave
On Thu, Feb 28, 2019 at 3:09 PM <helloworldsuperd...@gmail.com> wrote: > > > On Thursday, February 28, 2019 at 1:47:36 PM UTC-5, helloworl...@gmail.com > wrote: >> >> I have a Bottom Sheet that opens and has a textarea element for users to >> enter a message. I want this to be auto-focused but I'm pulling the little >> bit of hair I have left trying to get this trivial little thing to work. >> The html autofocus does not work here. I have tried the ViewChild thing and >> used this code in different lifecyle hooks: >> this.el.nativeElement.focus(); >> I have created custom directives using two different examples. Nothing >> works. Oddly, when I use the ViewChild method I can create a test button >> and run the above code and it gives the element focus as expected. But I >> run the same code inside a lifecycle hook like ngOnInit or ngAfterViewInit >> or ngAfterContentInit, it doesn't work. How can that make sense? Oh, and >> I've tried the Renderer 2 thing. That only resulted in more hair loss. I've >> triple checked my code against several examples I found Googling. But >> nothing works. Please help, I want to keep the few hairs I have left. >> Thanks. >> Dave >> > -- > You received this message because you are subscribed to the Google Groups > "Angular and AngularJS discussion" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to angular+unsubscr...@googlegroups.com. > To post to this group, send email to angular@googlegroups.com. > Visit this group at https://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscr...@googlegroups.com. To post to this group, send email to angular@googlegroups.com. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.