Ion-textarea autofocus only fires once

Hi I’m new to ionic. I have an ion-textarea inside a modal and I have noticed that autofocus only fires once. Is this a normal behaviour ? I want the ion-textarea to autofocus every time the modal is opened.

My code for the textarea is below and it is outside ion-content.

<div style="border-top: .3px solid rgb(219, 219, 219);" *ngIf="this.thisCommentCount == '0' ">
    <ion-item lines="none" style="height: auto;  " >

        <ion-textarea 
        formControlName="comment" 
        placeholder="Write a comment..." 
        rows="1"
        auto-grow="true"
        autofocus="true"
        mode="ios"
        maxlength="1000"
        style=""
        >

      </ion-textarea>

</ion-item>
</div>
    </form>

You could try using the setFocus() method in your component’s ts file. You would have to get the text area into that element using @ViewChild

Thanks, is there an example you can find? I’m a beginner at coding.

Here is an example of something similar I did with a searchbar instead of a text-area:

HTML

<ion-searchbar #searchbar></ion-searchbar>

Component

@ViewChild('searchbar', {read: IonSearchbar}) searchbar: IonSearchbar;

async ngOnInit() {
    await this.searchbar.setFocus();
    // If you want the keyboard to also show
    await Keyboard.show();
  }
1 Like