Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LinkButton does not open in new tab #1047

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/strapi-design-system/src/v2/LinkButton/LinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,23 @@ const LinkWrapper = styled(BaseButtonWrapper)`

export const LinkButton = React.forwardRef<HTMLAnchorElement, LinkButtonProps>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation of the Flex and Box components is currently limited due to the utilization of the shouldForwardProp function from styled-components. While it functions well for the majority of use cases, it can pose challenges when we utilize the as property to bind a different component for rendering in the DOM, as the necessary props are not forwarded to the component.

To illustrate this behavior, here's a brief demonstration.

(
{ variant = 'default', startIcon, endIcon, disabled = false, children, size = 'S', as = BaseLink, ...props },
{
variant = 'default',
startIcon,
endIcon,
disabled = false,
children,
isExternal,
size = 'S',
as = BaseLink,
...props
},
ref,
) => {
const paddingX = size === 'S' ? 2 : '10px';
const paddingY = 4;
const target = isExternal ? '_blank' : undefined;
const rel = isExternal ? 'noreferrer noopener' : undefined;

return (
<LinkWrapper
Expand All @@ -64,6 +76,8 @@ export const LinkButton = React.forwardRef<HTMLAnchorElement, LinkButtonProps>(
paddingRight={paddingY}
paddingTop={paddingX}
pointerEvents={disabled ? 'none' : undefined}
target={target}
rel={rel}
{...props}
as={as || BaseLink}
>
Expand Down