简体   繁体   English

Vuetify v-select 不支持键盘 Tab 键

[英]Vuetify v-select does not support keyboard tab key

I have the form below for users.我有下面的表格供用户使用。 The issue here is when I am on first_name field and I press tab key on the keyboard it takes me to the last_name field.这里的问题是,当我在 first_name 字段上并按键盘上的 Tab 键时,它会将我带到 last_name 字段。 When I press tab key when I am on last_name field it skips the city field and goes directly to the phone_number field.当我在 last_name 字段上按 Tab 键时,它会跳过城市字段并直接转到 phone_number 字段。 I have to click on city field to select the city.我必须点击城市字段到 select 这个城市。 Tab key doesn't take me to v-select. Tab 键不会让我选择 v-select。 I am using vuetify version 2.3.10.我正在使用 vuetify 版本 2.3.10。 I am not able to figure out a work around for this.我无法为此找到解决方法。 Any idea how this can be resolved?知道如何解决这个问题吗?

<template>
  <div>
    <v-form :model='user'>
      <v-text-field
       label='First Name'
       v-model='user.first_name'>
      </v-text-field>
      <v-text-field
       label='Last Name'
       v-model='user.last_name'>
      </v-text-field>
      <v-select 
       :items="cities"
       attach
       item-text='name'
       item-value='name'
       v-model="user.city"
       label="City">
      </v-select>
      <v-text-field
       label='Phone Number'
       v-model='user.phone_number'>
      </v-text-field>
    </v-form>
  </div>
</template>

v-select logically is text input, and the opened list is v-list-item , so if you want the list open on focus you have to add code like this to your v-select v-select逻辑上是text输入,打开的列表是v-list-item ,所以如果你想在焦点上打开列表,你必须将这样的代码添加到你的v-select

<v-select 
  @focus="($event) => {$event.target.click()}"
<v-select 

Here is Codepen这是代码笔

I just had this problem because I had followed the advice in this issue thread earlier on.我只是遇到了这个问题,因为我早些时候遵循了这个问题线程中的建议。 By setting the v-select's input style to display: none , the browser no longer focuses on it with the tab key.通过将 v-select 的输入样式设置为display: none ,浏览器不再用 tab 键关注它。

The fix is to use the following styles instead, which set the input's width to 0 instead of hiding it completely:修复方法是改用以下 styles,它将输入的宽度设置为 0 而不是完全隐藏它:

.v-select__selections input {
    width: 0 !important;
    max-width: 0 !important;
}
.v-select__selections .v-select__selection {
    max-width: none;
}

You can use only @focus="$event.target.click()" in focus event.您只能在焦点事件中使用@focus="$event.target.click()" It works for me.这个对我有用。

<v-select
    label="Choose Item"
    v-model="item_id"
    :items="items"
    item-text="name"
    item-value="id"
    @focus="$event.target.click()">
</v-select>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM