# Auto-focus to ion-input Ionic v4

**URL:** <https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422>\
**Category:** ionic-v3\
**Created:** [August 23, 2018, 10:53am UTC](https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422 "2018-08-23T10:53:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vigupe](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vigupe](https://forum.ionicframework.com/u/vigupe)\
**Post date:** [August 23, 2018, 10:53am UTC](https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422/1 "2018-08-23T10:53:47Z")

</div>

I am doing the migration of an ionic v3 app to ionic v4. I have encountered the problem that when doing the auto-focus on an ion-input the way to do it in ionic v3 does not work, I tried to create a directive to perform the auto-focus, but it has not helped me.

Have you encountered the same problem?

Thanks.

**Ionic v3 auto-focus code:**  
_.ts file:_

```auto

import { ViewChild } from '@angular/core';

@Component({
  selector: 'page-inventario',
  templateUrl: 'inventario.html'
})

export class InventarioPage{
  @ViewChild('inputInventarioCB') CBProductoInventario;
ionViewDidEnter() {
    this.focusInput(this.CBProductoInventario);
  }

  focusInput(input) {
    if(this.timer){
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(() => {
      input.setFocus();
    },1000);
  }

}

```

_.html file:_

`<ion-input #inputInventarioCB type="text" placeholder="Código de barras" required [(ngModel)]="producto.codigoBarras" name="codigoBarras" (keypress)="controlTeclaIntro($event, codigoBarras)"</ion-input>`

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [August 23, 2018, 11:24am UTC](https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422/2 "2018-08-23T11:24:21Z")

</div>

I think it isn’t there yet, but, how lucky you are, the very last commit in the Ionic project added by @manucorporat is the feature you are looking for [https://github.com/ionic-team/ionic/commit/c66a34ab596bf1dc944c1f753b2e356a91348fc4](https://github.com/ionic-team/ionic/commit/c66a34ab596bf1dc944c1f753b2e356a91348fc4)

You should be good in next beta

---

<div class="post-metadata">

**Author:** ![vigupe](https://avatars.discourse-cdn.com/v4/letter/v/ee7513/32.png) [@vigupe](https://forum.ionicframework.com/u/vigupe)\
**Post date:** [August 23, 2018, 11:39am UTC](https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422/3 "2018-08-23T11:39:27Z")

</div>

Thanks, I’ll take a look.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:22pm UTC](https://forum.ionicframework.com/t/auto-focus-to-ion-input-ionic-v4/139422/4 "2021-07-19T21:22:46Z")

</div>

Closed on July 19, 2021, 9:22pm UTC


