Skip to content

Commit

Permalink
NavLink also accept Link properties, fixed #1563 (#1564)
Browse files Browse the repository at this point in the history
(cherry picked from commit 586c457)
  • Loading branch information
hermantolim authored and Sampo Kivistö committed Aug 21, 2021
1 parent 521a4c3 commit 6480b05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 15 additions & 0 deletions packages/inferno-router/__tests__/NavLink.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,19 @@ describe('NavLink', () => {
expect(node.textContent).toEqual('Pasta!');
});
});

describe('html link attributes', () => {
it('accept html link attributes', () => {
render(
<MemoryRouter initialEntries={['/pasta']}>
<NavLink to="/pasta" title="pasta">
Pasta!
</NavLink>
</MemoryRouter>,
node
);
const a = node.getElementsByTagName('a')[0];
expect(a.title).toEqual('pasta');
})
})
});
8 changes: 3 additions & 5 deletions packages/inferno-router/src/NavLink.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { createComponentVNode, VNode } from 'inferno';
import { VNodeFlags } from 'inferno-vnode-flags';
import { Route } from './Route';
import { Link } from './Link';
import {ILinkProps, Link} from './Link';
import { combineFrom } from 'inferno-shared';
import type { Location } from 'history';

function filter(i) {
return i;
}

interface NavLinkProps {
interface NavLinkProps extends ILinkProps {
to: string | Location;
exact?: boolean;
strict?: boolean;
onClick?: any;
location?: any;
activeClassName?: string;
className?: string;
activeStyle?: any;
style?: any;
isActive?: (match, location) => boolean;
Expand All @@ -40,7 +38,7 @@ export function NavLink({
isActive: getIsActive,
ariaCurrent = 'true',
...rest
}: NavLinkProps): any {
}: NavLinkProps & LinkHTMLAttributes<HTMLLinkElement>): any {
function linkComponent({ location, match }): VNode {
const isActive = Boolean(getIsActive ? getIsActive(match, location) : match);

Expand Down

0 comments on commit 6480b05

Please sign in to comment.