Skip to content

Commit

Permalink
feat(PageItem): implement "as" property (#6754)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilame committed Jan 17, 2024
1 parent 8518c68 commit 430b0c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/PageItem.tsx
Expand Up @@ -52,11 +52,12 @@ const PageItem: BsPrefixRefForwardingComponent<'li', PageItemProps> =
children,
linkStyle,
linkClassName,
as = Anchor,
...props
}: PageItemProps,
ref,
) => {
const Component = active || disabled ? 'span' : Anchor;
const Component = active || disabled ? 'span' : as;
return (
<li
ref={ref}
Expand Down
12 changes: 12 additions & 0 deletions test/PageItemSpec.tsx
Expand Up @@ -67,5 +67,17 @@ describe('<PageItem>', () => {

pageItemInnerElem.getAttribute('style')!.should.equal('color: red;');
});

it('should support custom anchor element', () => {
const Component = ({ children, ...props }) => (
<a {...props} data-anchor="custom">
{children}
</a>
);
const { container } = render(<PageItem as={Component} />);
const pageItemElem = container.firstElementChild!;
const pageItemInnerElem = pageItemElem.firstElementChild!;
pageItemInnerElem.getAttribute('data-anchor')!.should.equal('custom');
});
});
});

0 comments on commit 430b0c9

Please sign in to comment.