No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Autocomplete keep focus on input with custom menu

    Framework
    2
    6
    847
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ssuess
      ssuess last edited by

      I have an input field I am using for searches, and I have attached a menu to it with autocomplete suggestions that are pulled from an API call and update dynamically as the user types more input. This all works as expected, but I can’t figure out how to keep focus on my input as the user is typing if the menu of choices is active. Here is my template code:

      <q-input v-on:keyup.enter="searchMe(search);showing = false" @input="filterFn(search);showing = true;" @click="showing = true" v-model="search" filled type="search" style="width:100%;margin-top:0;">
          <template v-slot:append>
                <q-icon name="search" @click="searchMe(search)" style="cursor:pointer;"/>
              </template>
      <q-menu auto-close v-if="ACreturnoptions && showing" fit anchor="top left" self="top left" class="suggest" :offset="[0, -50]">
        <template v-for="(parent, i) in ACreturnoptions">
        <q-item-label :key="`${parent.category}-${i}`" class="q-pa-sm">{{ parent.category }}</q-item-label>
        <q-separator :key="`${parent.category}-${i}`" />
        <template v-for="(child, index) in parent.suggestions">
        <q-item clickable @click.native="searchMe(child.value);" :key="`${i}-${index}`">
          <q-item-section>{{ child.label }}<q-item-label class="mlabel">{{ child.description }}</q-item-label></q-item-section>
        </q-item>
        </template>
        </template>
      </q-menu>
      </q-input>
      

      I have also tried setting the v-model on the menu to showing, and various combos of setting showing to true/false based on input or clicks in the input field.

      I just want the focus to remain on the input field while the user is typing, but still show the dropdown menu of choices (and its dynamic content updating as calls are made to the api). currently when the dropdown shows, the input field loses focus.

      Any suggestions?

      1 Reply Last reply Reply Quote 0
      • ssuess
        ssuess last edited by

        Not sure if this is the best way, but I did the following and it seems to work:

        1. I attached @show="setFocus()" to the q-menu
        2. I run my method setFocus to set the focus to the my search input field
        1 Reply Last reply Reply Quote 0
        • ssuess
          ssuess last edited by

          Well, this is only a partial fix. Unfortunately this results in a slight keyboard pause when someone is entering data in the field when it is first triggered, meaning that key stroke is not captured. Any one have any suggestions?

          1 Reply Last reply Reply Quote 0
          • metalsadman
            metalsadman last edited by

            Maybe post a pen of how you are doing it imo.

            1 Reply Last reply Reply Quote 0
            • ssuess
              ssuess last edited by

              I found out what was causing the delay. My methods on the input were checking if the platform was mobile first if (!this.$q.platform.is.mobile) { this.showing = true } before setting the menu to show, and that somehow was causing a delay. If I remove that check (and instead set the value of a data item to this.$q.platform.is.mobile) I can check against that in the template itself and it now works without delay, go figure.

              1 Reply Last reply Reply Quote 0
              • metalsadman
                metalsadman last edited by

                @ssuess yep, and you never included that in your code above, always better to make a bare bones reproduction pen, so peeps can help out faster ;).

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post