|
1 | 1 | # vue-skip-to
|
2 |
| -It helps people who only use the keyboard to jump to what matters most |
| 2 | + |
| 3 | +> Helps people who only use the keyboard to jump to what matters most |
| 4 | +
|
| 5 | +- [Installation](##installation) |
| 6 | +- [Usage](##usage) |
| 7 | +- [Props](##props) |
| 8 | +- [Custom styling](##custom-styling) |
| 9 | +- [Running tests](##running-tests) |
| 10 | +- [About](##about) |
| 11 | +- [Contributing](##contributing) |
3 | 12 |
|
4 | 13 | 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?
|
5 | 14 |
|
6 | 15 | However, we are responsible for doing our utmost to make our applications usable and accessible to everyone.
|
7 | 16 |
|
8 | 17 | "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.
|
9 | 18 |
|
10 |
| -In addition to being a technique recommended by WCAG 2.0, that's where this component was inspired. |
11 |
| -https://www.w3.org/TR/WCAG20-TECHS/G1.html |
12 |
| -https://www.w3.org/TR/WCAG20-TECHS/G124.html |
| 19 | +This pattern is detailed in the Techniques for WCAG 2.0 in notes [G1](https://www.w3.org/TR/WCAG20-TECHS/G1.html) and [G124](https://www.w3.org/TR/WCAG20-TECHS/G124.html), and also served as the inspiration for creating this component. |
13 | 20 |
|
14 |
| -## Install |
15 |
| -#### NPM |
16 |
| -```shell |
17 |
| -npm install -S vue-skip-to |
18 |
| -``` |
| 21 | +[Check out the live demo!](https://vue-skip-to.surge.sh) |
| 22 | + |
| 23 | +## Installation |
19 | 24 |
|
20 |
| -#### Yarn |
21 | 25 | ```shell
|
22 |
| -yarn add vue-skip-to |
| 26 | +// npm |
| 27 | +npm install -S @vue-a11y/skip-to |
| 28 | + |
| 29 | +// yarn |
| 30 | +yarn add @vue-a11y/skip-to |
23 | 31 | ```
|
24 | 32 |
|
25 |
| -## How to use |
26 |
| -In your `main.js` |
| 33 | +## Usage |
| 34 | + |
| 35 | +### Vue SFC |
| 36 | + |
27 | 37 | ```javascript
|
| 38 | +// main.js |
| 39 | + |
28 | 40 | import Vue from 'vue'
|
29 |
| -import VueSkipTo from 'vue-skip-to' |
| 41 | +import VueSkipTo from '@vue-a11y/skip-to' |
30 | 42 |
|
31 | 43 | Vue.use(VueSkipTo)
|
32 | 44 |
|
33 | 45 | new Vue({
|
34 |
| - //... options |
| 46 | + //... |
35 | 47 | })
|
36 | 48 | ```
|
37 | 49 |
|
38 |
| -In your `App.vue` |
39 | 50 | ```vue
|
| 51 | +// App.vue |
| 52 | +
|
40 | 53 | <template>
|
41 | 54 | <div id="app">
|
42 |
| - <vue-skip-to to="#main" text="Skip to main content" /> |
43 |
| -
|
44 |
| - <logo :src="require('@/assets/logo.png')" /> |
45 |
| - <h1 data-va="main header">{{ msg }}</h1> |
46 |
| - ... |
47 |
| - <div id="main" role="main"> |
48 |
| - <!-- My content --> |
49 |
| - </div> |
| 55 | + <VueSkipTo to="#main" label="Skip to main content" /> |
| 56 | +
|
| 57 | + <!-- header, navigation, and more --> |
| 58 | +
|
| 59 | + <main id="main"> |
| 60 | + <!-- content --> |
| 61 | + </main> |
50 | 62 | </div>
|
51 | 63 | </template>
|
| 64 | +
|
52 | 65 | <script>
|
53 | 66 | export default {
|
54 | 67 | name: 'app'
|
55 | 68 | components: {
|
56 |
| - Logo |
| 69 | + Logo, |
| 70 | + VueSkipTo, |
57 | 71 | },
|
58 | 72 | //...
|
59 | 73 | }
|
60 | 74 | </script>
|
61 | 75 | ```
|
62 | 76 |
|
63 |
| -## Using with HTML files |
| 77 | +#### Skip-to list |
| 78 | + |
| 79 | +To use multiple links, simply pass an array into the `to` prop with the following shape: |
| 80 | + |
| 81 | +```js |
| 82 | +[ |
| 83 | + { |
| 84 | + "anchor": "<STRING>", // destination id |
| 85 | + "label": "<STRING>" // link text |
| 86 | + } |
| 87 | + //... |
| 88 | +] |
| 89 | +``` |
| 90 | + |
| 91 | +```vue |
| 92 | +// App.vue |
| 93 | +
|
| 94 | +<template> |
| 95 | + <div id="app"> |
| 96 | + <vue-skip-to |
| 97 | + list-label="Skip to" |
| 98 | + :to="[ |
| 99 | + { anchor: '#main', label: 'Main content' }, |
| 100 | + { anchor: '#footer', label: 'Footer' }, |
| 101 | + ]" |
| 102 | + ></vue-skip-to> |
| 103 | +
|
| 104 | + <!-- header, navigation, and more --> |
| 105 | +
|
| 106 | + <main id="main"></div> |
| 107 | +
|
| 108 | + <footer id="footer"></div> |
| 109 | + </div> |
| 110 | +</template> |
| 111 | +``` |
| 112 | + |
| 113 | +### In HTML files |
| 114 | + |
64 | 115 | ```html
|
65 | 116 | <!--omitted -->
|
| 117 | + <script src="https://unpkg.com/vue"></script> |
| 118 | + <script src="https://unpkg.com/@vue-a11y/skip-to"></script> |
| 119 | +</head> |
66 | 120 | <body>
|
67 | 121 | <div id="app">
|
68 | 122 | <vue-skip-to to="#main"></vue-skip-to>
|
69 | 123 |
|
70 |
| - <!-- my header, navigation, and more --> |
| 124 | + <!-- header, navigation, and more --> |
71 | 125 |
|
72 |
| - <div id="main" role="main"> |
73 |
| - <!-- My content --> |
74 |
| - </div> |
| 126 | + <main id="main"> |
| 127 | + <!-- content --> |
| 128 | + </main> |
75 | 129 | </div>
|
76 | 130 |
|
77 |
| - <script src="https://unpkg.com/vue"></script> |
78 |
| - <script src="https://unpkg.com/vue-skip-to"></script> |
79 | 131 | <script>
|
80 |
| - Vue.use(VueSkipTo) |
81 | 132 | new Vue({
|
82 | 133 | el: "#app"
|
83 | 134 | })
|
84 |
| -
|
85 | 135 | </script>
|
86 | 136 | </body>
|
87 | 137 | </html>
|
88 | 138 | ```
|
89 | 139 |
|
90 |
| -## Check live demo |
91 |
| -https://vue-skip-to.surge.sh |
92 |
| - |
93 |
| - |
94 | 140 | ## Props
|
95 |
| -Prop | Data Type | required | Description | Default |
96 |
| ---------------- | ---------- | --------- | ---------------------- | ------------- |
97 |
| -`to` | String | false | Set destination ID | #main |
98 |
| -`text` | String | false | Text content of link | Skip to main content |
99 |
| -`tabindex` | String | false | Specifies the tab order | null |
100 | 141 |
|
| 142 | +| Prop | Data Type | required | Description | Default | |
| 143 | +| ------------ | --------------- | -------- | ----------------------------------------------------------------- | ---------------------- | |
| 144 | +| `to` | String \| Array | false | Destination ID or [array of destination objects](###skip-to-list) | '#main' | |
| 145 | +| `label` | String | false | Skip link text content | 'Skip to main content' | |
| 146 | +| `list-label` | String | false | Skip link list label text | 'Skip to' | |
101 | 147 |
|
102 |
| -## Custom style |
103 |
| -You can style the link through the selector `.vue-skip-to` |
| 148 | +## Custom styling |
104 | 149 |
|
105 |
| -## Feature |
106 |
| -Inspired by this article, to know more, access the link: |
107 |
| -http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ |
| 150 | +Override the default styles by targeting the following: |
108 | 151 |
|
109 |
| -- This component working in all modern browsers and IE9; |
110 |
| -- 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`; |
111 |
| -- Add focus to the destination, even when the address bar already has the corresponding hash; |
| 152 | +```css |
| 153 | +.vue-skip-to { |
| 154 | +} |
| 155 | +.vue-skip-to__link { |
| 156 | +} |
| 157 | +.vue-skip-to__nav { |
| 158 | +} |
| 159 | +.vue-skip-to__nav-list { |
| 160 | +} |
| 161 | +.vue-skip-to__nav-list-item { |
| 162 | +} |
| 163 | +``` |
112 | 164 |
|
113 |
| -## Run the tests |
| 165 | +## Running tests |
114 | 166 |
|
115 | 167 | ```shell
|
116 |
| -git clone https://github.com/vue-a11y/vue-skip-to.git vue-skip-to |
| 168 | +git clone https://github.com/vue-a11y/vue-skip-to.git |
117 | 169 | npm install
|
118 | 170 | npm run dev
|
119 |
| -npm run test |
| 171 | +npm run test:e2e |
120 | 172 | ```
|
121 | 173 |
|
122 | 174 | Or run Cypress on interactive mode
|
| 175 | + |
123 | 176 | ```shell
|
124 |
| -npm run test:open |
| 177 | +npm run test:e2e:open |
125 | 178 | ```
|
126 | 179 |
|
127 |
| -## Roadmap |
128 |
| -https://github.com/vue-a11y/vue-skip-to/issues/1 |
| 180 | +## About |
| 181 | + |
| 182 | +This component was inspired by [this article](http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/). |
| 183 | + |
| 184 | +- This component working in all modern browsers and IE9; |
| 185 | +- 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`; |
| 186 | +- Add focus to the destination, even when the address bar already has the corresponding hash; |
129 | 187 |
|
130 | 188 | ## Contributing
|
| 189 | + |
| 190 | +- From typos in documentation to coding new features; |
131 | 191 | - Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found;
|
132 | 192 | - Fork repository, make changes and send a pull request;
|
133 | 193 |
|
134 |
| -If you want a faster communication, find me on [@ktquez](https://twitter.com/ktquez) |
135 |
| -And follow us on Twitter [@vue_a11y](https://twitter.com/vue_a11y) |
| 194 | +Follow us on Twitter [@vue_a11y](https://twitter.com/vue_a11y) |
136 | 195 |
|
137 | 196 | **Thank you**
|
0 commit comments