Skip to content

It helps people who only use the keyboard to jump to what matters most.

License

Notifications You must be signed in to change notification settings

vue-a11y/vue-skip-to

vue-skip-to


🔥 HEADS UP! You are in the Vue 2 compatible branch, check the branch for Vue 3 support.


Helps people who only use the keyboard to jump to what matters most

The population grows very fast nowadays and with that the number of visually impaired increases as well. Did you know that we have over 350 million visually impaired people in the world?

However, we are responsible for doing our utmost to make our applications usable and accessible to everyone.

"Skip to content" or "skip to a section" of your site is one of the most common accessibility techniques today, but not as used as it should be.

This pattern is detailed in the Techniques for WCAG 2.0 in notes G1 and G124, and also served as the inspiration for creating this component.

Check out the live demo!

Installation

// npm npm install -S @vue-a11y/skip-to // yarn yarn add @vue-a11y/skip-to

Usage

Vue SFC

// main.jsimportVuefrom'vue'importVueSkipTofrom'@vue-a11y/skip-to'Vue.use(VueSkipTo)newVue({//...})
// App.vue <template> <divid="app"> <VueSkipToto="#main"label="Skip to main content" /> <!-- header, navigation, and more --> <mainid="main"> <!-- content --> </main> </div> </template> <script>exportdefault{ name:'app' components:{ Logo, VueSkipTo, },//...}</script>

Skip-to list

To use multiple links, set an array into the to prop with the following shape:

[{"anchor": "<STRING>",// destination id"label": "<STRING>"// link text}//...]
// App.vue <template> <divid="app"> <vue-skip-tolist-label="Skip to":to="[{anchor: '#main', label: 'Main content' },{anchor: '#footer', label: 'Footer' }, ]" ></vue-skip-to> <!-- header, navigation, and more --> <mainid="main"></div> <footerid="footer"></div> </div> </template>

In HTML files

<!--omitted --><scriptsrc="https://unpkg.com/vue"></script><scriptsrc="https://unpkg.com/@vue-a11y/skip-to"></script></head><body><divid="app"><vue-skip-toto="#main"></vue-skip-to><!-- header, navigation, and more --><mainid="main"><!-- content --></main></div><script>newVue({el: "#app"})</script></body></html>

Props

PropData TyperequiredDescriptionDefault
toString | ArrayfalseDestination ID or array of destination objects'#main'
labelStringfalseSkip link text content'Skip to main content'
list-labelStringfalseSkip link list label text'Skip to'

Support route change

@vue-a11y/skip-to checks if you are using the vue-router, watches changes to $route.path and send focus to the vue-skip-to wrapper.

Recommendation: To make more sense, use the VueSkipTo component right after the root element of your app.

Read more about accessible routing:

Custom styling

Override the default styles by targeting the following:

.vue-skip-to{} .vue-skip-to__link{} .vue-skip-to__nav{} .vue-skip-to__nav-list{} .vue-skip-to__nav-list-item{}

Running tests

git clone https://github.com/vue-a11y/vue-skip-to.git npm install npm run dev npm run test:e2e

Or run Cypress on interactive mode

npm run test:e2e:open

About

This component was inspired by this article.

  • This component working in all modern browsers and IE9;
  • Ensures that the target element receives focus, even if it is not a tag that naturally receives focus as the tag input and a. In this case, the div are also given the focus and the tabindex attribute with the value of -1;
  • Add focus to the destination, even when the address bar already has the corresponding hash;

Contributing

  • From typos in documentation to coding new features;
  • Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found;
  • Fork repository, make changes and send a pull request;

Follow us on Twitter @vue_a11y

Thank you

About

It helps people who only use the keyboard to jump to what matters most.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors 3

    •  
    •  
    •