diff --git a/.changeset/orange-beans-matter.md b/.changeset/orange-beans-matter.md new file mode 100644 index 000000000..29f5845b7 --- /dev/null +++ b/.changeset/orange-beans-matter.md @@ -0,0 +1,5 @@ +--- +"@rspress/theme-default": patch +--- + +feat: pass through HTMLAnchorElement props to Link component. diff --git a/packages/theme-default/src/components/Link/index.tsx b/packages/theme-default/src/components/Link/index.tsx index b7423fdc9..821acf505 100644 --- a/packages/theme-default/src/components/Link/index.tsx +++ b/packages/theme-default/src/components/Link/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { ComponentProps } from 'react'; import { matchRoutes, useLocation, @@ -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; @@ -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; @@ -81,6 +81,7 @@ export function Link(props: LinkProps) { if (!isExternal) { return ( ) => {