Skip to content

Commit

Permalink
fix(link): allow custom classes (#134)
Browse files Browse the repository at this point in the history
Fix #133
  • Loading branch information
wietseva authored Mar 12, 2020
1 parent 1adf36b commit 392c295
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions __tests__/RouterLink.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ describe('RouterLink', () => {
function factory(
currentLocation: RouteLocationNormalized,
propsData: any,
resolvedLocation: RouteLocationNormalized
resolvedLocation: RouteLocationNormalized,
template: string = `<RouterLink :to="to">a link</RouterLink>`
) {
const router = {
history: createMemoryHistory(),
Expand All @@ -120,7 +121,7 @@ describe('RouterLink', () => {

router.resolve.mockReturnValueOnce(resolvedLocation)
const { app, el } = mount(router as any, {
template: `<RouterLink :to="to">a link</RouterLink>`,
template,
components: { RouterLink } as any,
setup() {
return { to: propsData.to }
Expand Down Expand Up @@ -171,6 +172,17 @@ describe('RouterLink', () => {
expect(el.querySelector('a')!.className).toContain('router-link-active')
})

it('can be active with custom class', () => {
const { el } = factory(
locations.basic.normalized,
{ to: locations.basic.string },
locations.basic.normalized,
`<RouterLink class="nav-item" :to="to">a link</RouterLink>`
)
expect(el.querySelector('a')!.className).toContain('router-link-active')
expect(el.querySelector('a')!.className).toContain('nav-item')
})

it('is not active with more repeated params', () => {
const { el } = factory(
locations.repeatedParams2.normalized,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export const Link = defineComponent({
return h(
'a',
{
...attrs,
class: elClass.value,
onClick: link.navigate,
href: link.href,
...attrs,
},
slots.default && slots.default(link)
)
Expand Down

0 comments on commit 392c295

Please sign in to comment.