ModusCreateOrg / ionic-vue

Vuejs integration for Ionic versions 4 and 5
MIT License
272 stars 26 forks source link

Calling Ionic component method #87

Closed WayneDanielSinclair closed 5 years ago

WayneDanielSinclair commented 5 years ago
  <ion-searchbar @keyup.enter="dismissModal" ref="searchbar"></ion-searchbar>

  mounted: function() {
    this.$refs.searchbar.setFocus()
  },

I am trying to set the focus on an ion-searchbar. I would expect the above to work. https://ionicframework.com/docs/api/searchbar#methods Am I missing something or is this not supported?

I have tried working around it by trying to call the native focus function on the actual input element that is created but have not had success getting the input from the children of the ion-searchbar

michaeltintiuc commented 5 years ago

This should be supported as there are no wrapper around this ionic element. It should be same as using it in plain JS, I'll give it a try and report back

michaeltintiuc commented 5 years ago

@WayneDanielSinclair From the test that I did it indeed does not set focus when called from mounted but I believe this to be a browser issue as it works just fine when called via a click handler or any other user interaction.

michaeltintiuc commented 5 years ago

Actually scratch that, it does work with a timeout as per this: https://github.com/ionic-team/ionic/issues/17745

mounted() {
  setTimeout(() => this.$refs.searchbar.setFocus(), 1)
}
WayneDanielSinclair commented 5 years ago

Ok thanks for looking into that.