最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to remove the Vuetify append-icon from the sequential keyboard navigation - Stack Overflow

programmeradmin5浏览0评论

In a Vue.js app with Vuetify, I have a set of password fields defined with a v-text-field and which have an append-icon in order to switch the text visibility, as follows:

      <v-text-field
        v-model="password"
        :append-icon="show1 ? 'mdi-eye' : 'mdi-eye-off'"
        :type="show1 ? 'text' : 'password'"
        @click:append="show1 = !show1"
      ></v-text-field>

It is exactly similar to the documentation example for password input (See also the corresponding codepen).

With this set-up, if a user uses the Tab key to navigate across the different fields (sequential keyboard navigation), the append-icons are included in the sequential keyboard navigation.

I would like to exclude these icons from this sequential keyboard navigation (and be able to jump from one password field to the other without navigating to the append-icon).

Standard way to do that is to assign a "negative value (usually tabindex="-1")" which "means that the element is not reachable via sequential keyboard navigation", as explained here.

But I don't find how to assign a tab-index value only to the append-icon and not to the v-text-field itself.

In a Vue.js app with Vuetify, I have a set of password fields defined with a v-text-field and which have an append-icon in order to switch the text visibility, as follows:

      <v-text-field
        v-model="password"
        :append-icon="show1 ? 'mdi-eye' : 'mdi-eye-off'"
        :type="show1 ? 'text' : 'password'"
        @click:append="show1 = !show1"
      ></v-text-field>

It is exactly similar to the documentation example for password input (See also the corresponding codepen).

With this set-up, if a user uses the Tab key to navigate across the different fields (sequential keyboard navigation), the append-icons are included in the sequential keyboard navigation.

I would like to exclude these icons from this sequential keyboard navigation (and be able to jump from one password field to the other without navigating to the append-icon).

Standard way to do that is to assign a "negative value (usually tabindex="-1")" which "means that the element is not reachable via sequential keyboard navigation", as explained here.

But I don't find how to assign a tab-index value only to the append-icon and not to the v-text-field itself.

Share Improve this question asked Apr 22, 2020 at 10:08 Renaud TarnecRenaud Tarnec 83.2k10 gold badges98 silver badges129 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

You could use v-slot:append and place the icon there.

<v-text-field v-model="password" :type="show1 ? 'text' : 'password'">
  <template v-slot:append>
    <v-button @click="show1 = !show1" tabindex="-1">
      <v-icon v-if="show1" >mdi-eye</v-icon>
      <v-icon v-if="show1" >mdi-eye-off</v-icon>
    </v-button>
  </template>
</v-text-field>

However, it's not because you can do this that you should. If you place this button outside of reach of tabindex, someone with a screenreader might not be able to toggle the button.
From an accesibility concern, this button is an interactive element and thus should have tabindex="0"

What also worked for me is to just assign the tabindex for all elements. The append-icon will be ignored then.

<v-text-field 
  tabindex="1" 
  v-model="password" 
  :append-icon="show1 ? 'mdi-eye' : 'mdi-eye-off'" 
  :type="show1 ? 'text' : 'password'" 
  @click:append="show1 = !show1">
</v-text-field>
<v-btn tabindex="2" @click="submitForm">Submit</v-btn>
发布评论

评论列表(0)

  1. 暂无评论