Skip to content

Commit

Permalink
Add activeIcon to TopNavigation and SideNavigation links (#2295)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Nov 14, 2023
1 parent bd4e7ec commit 6c536a2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/young-ducks-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': minor
---

Added support for an `activeIcon` to the TopNavigation and SideNavigation links.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ describe('PrimaryLink', () => {
expect(getByRole('link')).toHaveAttribute('aria-current', 'page');
});

it('should render with an active icon', () => {
const { getByTestId } = renderPrimaryLink(render, {
...baseProps,
activeIcon: () => <div data-testid="active-icon" />,
isActive: true,
});
expect(getByTestId('active-icon')).toBeVisible();
});

it.todo('should render with an external icon');

it('should render with a suffix icon', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export interface PrimaryLinkProps extends PrimaryLinkType {
}

export function PrimaryLink({
icon: Icon,
icon,
activeIcon,
label,
isActive,
isExternal,
Expand All @@ -51,6 +52,8 @@ export function PrimaryLink({
);
const isExternalLink = isExternal || props.target === '_blank';

const Icon = isActive && activeIcon ? activeIcon : icon;

return (
<Element
{...props}
Expand Down
4 changes: 4 additions & 0 deletions packages/circuit-ui/components/SideNavigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export interface PrimaryLinkProps
* On narrow viewports, only the icon is displayed.
*/
icon: IconComponentType;
/**
* Display a different icon when the link is active.
*/
activeIcon?: IconComponentType;
/**
* Short label to describe the target of the link.
*/
Expand Down

0 comments on commit 6c536a2

Please sign in to comment.