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

feat: pass through HTMLAnchorElement props to Link component. #641

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-beans-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspress/theme-default": patch
---

feat: pass through HTMLAnchorElement props to Link component.
8 changes: 5 additions & 3 deletions packages/theme-default/src/components/Link/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ComponentProps } from 'react';
import {
matchRoutes,
useLocation,
Expand All @@ -14,7 +14,7 @@ import { isExternalUrl } from '@rspress/shared';
import styles from './index.module.scss';
import { scrollToTarget } from '#theme/logic';

export interface LinkProps {
export interface LinkProps extends ComponentProps<'a'> {
href?: string;
children?: React.ReactNode;
className?: string;
Expand All @@ -24,7 +24,7 @@ export interface LinkProps {
nprogress.configure({ showSpinner: false });

export function Link(props: LinkProps) {
const { href = '/', children, className = '', onNavigate } = props;
const { href = '/', children, className = '', onNavigate, ...rest } = props;
const isExternal = isExternalUrl(href);
const target = isExternal ? '_blank' : '';
const rel = isExternal ? 'noopener noreferrer' : undefined;
Expand Down Expand Up @@ -81,6 +81,7 @@ export function Link(props: LinkProps) {
if (!isExternal) {
return (
<a
{...rest}
className={`${styles.link} ${className} cursor-pointer`}
rel={rel}
target={target}
Expand All @@ -93,6 +94,7 @@ export function Link(props: LinkProps) {
} else {
return (
<a
{...rest}
href={withBaseUrl}
target={target}
rel={rel}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentProps } from 'react';
import { Link } from '../../../components/Link';
import styles from './index.module.scss';
import { Link } from '#theme/components/Link';
import { usePathUtils } from '#theme/logic';

export const A = (props: ComponentProps<'a'>) => {
Expand Down
Loading