Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Issue #494] New config option skipLink for accessibility #495

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,14 @@ window.$docsify = {
```
> Note: The options with fallbackLanguages didn't work with the `notFoundPage` options.


## skipLink

* type: `Boolean`

Add a [skip link](https://webaim.org/techniques/skipnav) to help with screen reader accessibility
```js
window.$docsify = {
skipLink: true
};
```
12 changes: 12 additions & 0 deletions docs/de-de/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,15 @@ window.$docsify = {
};
```
> Note: The options with fallbackLanguages didn't work with the `notFoundPage` options.


## skipLink

* type: `Boolean`

Add a [skip link](https://webaim.org/techniques/skipnav) to help with screen reader accessibility
```js
window.$docsify = {
skipLink: true
};
```
10 changes: 10 additions & 0 deletions docs/zh-cn/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,13 @@ window.$docsify = {
> Note: The options with fallbackLanguages didn't work with the `notFoundPage` options.


## skipLink

* type: `Boolean`

Add a [skip link](https://webaim.org/techniques/skipnav) to help with screen reader accessibility
```js
window.$docsify = {
skipLink: true
};
```
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
subMaxLevel: 2,
mergeNavbar: true,
formatUpdated: '{MM}/{DD} {HH}:{mm}',
skipLink: true,
plugins: [
function (hook, vm) {
hook.beforeEach(function (html) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"marked": "^0.3.12",
"medium-zoom": "^0.4.0",
"opencollective": "^1.0.3",
"prismjs": "^1.9.0",
"prismjs": "^1.13.0",
"tinydate": "^1.0.0",
"tweezer.js": "^1.4.0"
},
Expand Down
16 changes: 16 additions & 0 deletions src/core/render/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ function renderNameLink(vm) {
}
}

function updateSkipLink(vm) {
const skipLink = dom.getNode('#skip-link')
skipLink.href = `/#${vm.route.path}?id=main`
}

export function renderMixin(proto) {
proto._renderTo = function (el, content, replace) {
const node = dom.getNode(el)
Expand Down Expand Up @@ -202,6 +207,8 @@ export function renderMixin(proto) {
proto._updateRender = function () {
// Render name link
renderNameLink(this)
// Update skip-link link
updateSkipLink(this)
}
}

Expand Down Expand Up @@ -251,6 +258,15 @@ export function initRender(vm) {
dom.before(navAppendToTarget, navEl)
}

if (config.skipLink
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding this to <body></body> but <nav> was always added first

&& !dom.find('skip-link')) {
const skipLinkDom = dom.create('a')
skipLinkDom.id = 'skip-link'
skipLinkDom.href = '#/?id=main'
skipLinkDom.innerHTML = 'Skip to main content'
dom.before(dom.body, skipLinkDom)
}

if (config.themeColor) {
dom.$.head.appendChild(
dom.create('div', tpl.theme(config.themeColor)).firstElementChild
Expand Down
20 changes: 19 additions & 1 deletion src/themes/basic/_layout.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
body:not(.ready)
overflow hidden

[data-cloak], .app-nav, > nav
[data-cloak], .app-nav, > nav, #skip-link
display none

div#app
Expand Down Expand Up @@ -178,6 +178,24 @@ li input[type='checkbox']
height 80px
width 80px

#skip-link
position: absolute
top: -40px
left: 0px
outline: 0
padding: 0.5em 1em
color: transparent
background-color: transparent
z-index 30
transition: color .1s ease-in
transition: background-color .1s ease-in

&:focus
top: 0px
height: 40px
background-color: var(--theme-color, $color-primary)
color: $color-text

/* main */
main
display block
Expand Down