Skip to content

Commit 23e6e9c

Browse files
committed
feat(router-link): add ariaCurrentValue prop
1 parent 9e38637 commit 23e6e9c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/RouterLink.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,41 @@ import { RouteRecord } from './matcher/types'
1515
import { assign } from './utils'
1616

1717
export interface RouterLinkOptions {
18+
/**
19+
* Location the link should navigate to when clicked on.
20+
*/
1821
to: RouteLocationRaw
19-
// TODO: refactor using extra options allowed in router.push. Needs RFC
22+
/**
23+
* Calls `router.replace` instead of `router.push`.
24+
*/
2025
replace?: boolean
26+
// TODO: refactor using extra options allowed in router.push. Needs RFC
2127
}
2228

2329
export interface RouterLinkProps extends RouterLinkOptions {
30+
/**
31+
* Whether RouterLink should not wrap its content in an `a` tag.
32+
*/
2433
custom?: boolean
34+
/**
35+
* Class to apply when the link is active
36+
*/
37+
activeClass?: string
38+
/**
39+
* Class to apply when the link is exact active
40+
*/
41+
exactActiveClass?: string
42+
/**
43+
* Value passed to the attribute `aria-current` when the link is exact active. Defaults to "page"
44+
*/
45+
ariaCurrentValue?:
46+
| 'page'
47+
| 'step'
48+
| '___location'
49+
| 'date'
50+
| 'time'
51+
| 'true'
52+
| 'false'
2553
}
2654

2755
type UseLinkOptions = VueUseOptions<RouterLinkOptions>
@@ -101,6 +129,10 @@ export const RouterLinkImpl = defineComponent({
101129
// inactiveClass: String,
102130
exactActiveClass: String,
103131
custom: Boolean,
132+
ariaCurrentValue: {
133+
type: String as PropType<RouterLinkProps['ariaCurrentValue']>,
134+
default: 'page',
135+
},
104136
},
105137

106138
setup(props, { slots, attrs }) {
@@ -133,7 +165,9 @@ export const RouterLinkImpl = defineComponent({
133165
'a',
134166
assign(
135167
{
136-
'aria-current': link.isExactActive ? 'page' : null,
168+
'aria-current': link.isExactActive
169+
? props.ariaCurrentValue
170+
: null,
137171
onClick: link.navigate,
138172
href: link.href,
139173
},

vetur/attributes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,9 @@
2020
"exact-active-class": {
2121
"type": "string",
2222
"description": "Configure the active CSS class applied when the link is exactly active. Note the default value can also be configured globally via the `linkExactActiveClass` router constructor option."
23+
},
24+
"aria-current-value": {
25+
"options": ["page", "step", "___location", "date", "time", "true", "false"],
26+
"description": "Configure the value of `aria-current` when the link is active with exact match. It must be one of the [allowed values for `aria-current`](https://www.w3.org/TR/wai-aria-1.2/#aria-current) in the ARIA spec. In most cases, the default of `page` should be the best fit."
2327
}
2428
}

0 commit comments

Comments
 (0)