ionic-framework: bug: autofocus property has no effect on ion-input for desktop
Bug Report
Ionic version:
[x] 4.3.0
Current behavior:
If property autofocus is set to true for an <ion-input> element, the behavior for the <ion-input> element does not change when executing an ionic serve.
Expected behavior:
The app should focus on the <ion-input> element that has the property autofocus set to true.
Steps to reproduce:
- Insert
<ion-input autofocus="true"></ion-input>to your HTML page - Execute
ionic servein Ionic CLI - Wait for browser to pop up with app and observe behavior
Ionic info:
Ionic:
ionic (Ionic CLI) : 4.2.1
Ionic Framework : @ionic/angular 4.3.0
@angular-devkit/build-angular : 0.13.8
@angular-devkit/schematics : 7.2.4
@angular/cli : 7.3.8
@ionic/angular-toolkit : 1.4.1
System:
NodeJS : v8.12.0
npm : 6.4.1
OS : Windows 10
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 12
- Comments: 30 (2 by maintainers)
Thanks! My point is, if there’s a directive for it, should work as expected, anything else that adding that directive is a hack… this is a long existing issue.
how do we stir it up so it gets worked on? having a framework that does not do basic things it promises is making this framework irrelevant very quickly
Just in case, it still doesn’t work with the following Ionic / Capacitor configuration (tested on Android mobile device + browser)
And there is nothing fancy in the view…
@iva2k “to other” like what?
I can confirm this bug with Ionic 5.1.0 on Desktop/Safari, using the React
IonInputcomponent within anIonItem,IonContent,IonPage,IonApp(ordered from inside out).Here’s the workaround that I’m using:
useIonViewDidEnter(() => {setTimeout(() => inputRef.current.setFocus(), 100)})I gave up on Ionic, moving on to other, better things. Unsubscribe.
That’s how I do it in react. Not really a hack, just not as straightforward:
Still happens. I’m using plain JS, no framework https://jsbin.com/jadosag/1/edit?html,js,output
Thanks for the issue! I was able to reproduce this for both the native
inputandion-inputinside of anion-app. Outside of that tag it is working properly. Here’s the Codepen I made to reproduce: https://codepen.io/brandyscarney/pen/axXZGV?editors=1010Same issue here, just tried on iOS. autofocus does not work with Angular and Ionic 6.
[updating] - it seems like this did the trick… but why should i wait after view init? autofocus on the input does nothing
same issue on firefox linux with react
Workaroud for react :