Skip to content

.focus() on vs-input inside vs-popup not working #428

@ccalvarez

Description

@ccalvarez

Having this template code:

<vs-popup classContent="popup-example" title="Tarea" :active.sync="popupIsActive">
  <vs-input id="taskDescription" class="inputx" placeholder="Descripción de la tarea" v-model="taskDescription"/>
  <br>
   <vs-button
          id="setFocusButton"
          @click="setFocusOnInput()"
          color="primary"
          type="filled"
   >Set Focus on Input</vs-button>
</vs-popup>

I would like to set the focus on the vs-input control, each time the popup is loaded.

For that I have this watch:

  watch: {
    popupIsActive() {
      if (this.popupIsActive) {
        console.log(document.getElementById('taskDescription'));    // <==  the input exists in DOM
        document.getElementById('taskDescription').focus();         // <== but the focus is not set
      }
    },
  },

But the focus is not set.

Otherwise, if I click on the button, the focus is set:

 methods: {
    setFocusOnInput() {
      console.log(document.getElementById('taskDescription'));    // <==  the input exists in DOM
      document.getElementById('taskDescription').focus();         //  <== this time the focus is set
   },
},

I presume it has something to do with the hooks of vs-popup component, but I'm not really sure.

If anyone could point me at the right direction I would really appreciate it.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions