Skip to content

Commit

Permalink
Merge branch 'main' into fix/sidebar-label-hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyuan0704 authored Feb 22, 2024
2 parents e911841 + 4a73062 commit 8e45f16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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

0 comments on commit 8e45f16

Please sign in to comment.