Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(Links): Handling of link clicks when combined with keyboard function keys

haitaoo2258b9d12a37
diff --git a/ui/src/components/Header/components/NavItems/index.tsx b/ui/src/components/Header/components/NavItems/index.tsx
index 6f3cdf4d..392f814b 100644
--- a/ui/src/components/Header/components/NavItems/index.tsx
+++ b/ui/src/components/Header/components/NavItems/index.tsx
@@ -5,6 +5,7 @@ import { NavLink, useNavigate } from 'react-router-dom';
import type * as Type from '@/common/interface';
import { Avatar, Icon } from '@/components';
+import { floppyNavigation } from '@/utils';
interface Props {
redDot: Type.NotificationStatus | undefined;
@@ -16,10 +17,12 @@ const Index: FC<Props> = ({ redDot, userInfo, logOut }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const handleLinkClick = (evt) => {
- evt.preventDefault();
- const { href } = evt.currentTarget;
- const { pathname } = new URL(href);
- navigate(pathname);
+ if (floppyNavigation.shouldProcessLinkClick(evt)) {
+ evt.preventDefault();
+ const { href } = evt.currentTarget;
+ const { pathname } = new URL(href);
+ navigate(pathname);
+ }
};
return (
<>
diff --git a/ui/src/components/Header/index.tsx b/ui/src/components/Header/index.tsx
index eda36a03..62618528 100644
--- a/ui/src/components/Header/index.tsx
+++ b/ui/src/components/Header/index.tsx
@@ -70,10 +70,12 @@ const Header: FC = () => {
window.location.replace(window.location.href);
};
const onLoginClick = (evt) => {
- evt.preventDefault();
- floppyNavigation.navigateToLogin((loginPath) => {
- navigate(loginPath, { replace: true });
- });
+ if (floppyNavigation.shouldProcessLinkClick(evt)) {
+ evt.preventDefault();
+ floppyNavigation.navigateToLogin((loginPath) => {
+ navigate(loginPath, { replace: true });
+ });
+ }
};
useEffect(() => {
diff --git a/ui/src/components/Operate/index.tsx b/ui/src/components/Operate/index.tsx
index a4ea5ed1..d8b5d36d 100644
--- a/ui/src/components/Operate/index.tsx
+++ b/ui/src/components/Operate/index.tsx
@@ -13,6 +13,7 @@ import {
reopenQuestion,
} from '@/services';
import { tryNormalLogged } from '@/utils/guard';
+import { floppyNavigation } from '@/utils';
interface IProps {
type: 'answer' | 'question';
@@ -109,6 +110,9 @@ const Index: FC<IProps> = ({
}
};
const handleEdit = (evt, targetUrl) => {
+ if (!floppyNavigation.shouldProcessLinkClick(evt)) {
+ return;
+ }
evt.preventDefault();
let checkObjectId = qid;
if (type === 'answer') {
diff --git a/ui/src/components/Pagination/index.tsx b/ui/src/components/Pagination/index.tsx
index 40f220f1..6c3847ef 100644
--- a/ui/src/components/Pagination/index.tsx
+++ b/ui/src/components/Pagination/index.tsx
@@ -3,7 +3,7 @@ import { Pagination } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useSearchParams, useNavigate, useLocation } from 'react-router-dom';
-import { scrollToDocTop } from '@/utils';
+import { scrollToDocTop, floppyNavigation } from '@/utils';
interface Props {
currentPage: number;
@@ -48,10 +48,12 @@ const PageItem = ({ page, currentPage, path }: PageItemProps) => {
active={currentPage === page}
href={path}
onClick={(e) => {
- e.preventDefault();
- e.stopPropagation();
- navigate(path);
- scrollToDocTop();
+ if (floppyNavigation.shouldProcessLinkClick(e)) {
+ e.preventDefault();
+ e.stopPropagation();
+ navigate(path);
+ scrollToDocTop();
+ }
}}>
{page}
</Pagination.Item>
@@ -91,9 +93,11 @@ const Index: FC<Props> = ({
<Pagination.Prev
href={handleParams(currentPage - 1)}
onClick={(e) => {
- e.preventDefault();
- navigate(handleParams(currentPage - 1));
- scrollToDocTop();
+ if (floppyNavigation.shouldProcessLinkClick(e)) {
+ e.preventDefault();
+ navigate(handleParams(currentPage - 1));
+ scrollToDocTop();
+ }
}}>
{t('prev')}
</Pagination.Prev>
@@ -186,9 +190,11 @@ const Index: FC<Props> = ({
disabled={currentPage === totalPage}
href={handleParams(currentPage + 1)}
onClick={(e) => {
- e.preventDefault();
- navigate(handleParams(currentPage + 1));
- scrollToDocTop();
+ if (floppyNavigation.shouldProcessLinkClick(e)) {
+ e.preventDefault();
+ navigate(handleParams(currentPage + 1));
+ scrollToDocTop();
+ }
}}>
{t('next')}
</Pagination.Next>
diff --git a/ui/src/components/QueryGroup/index.tsx b/ui/src/components/QueryGroup/index.tsx
index f69e3596..7a6b0879 100644
--- a/ui/src/components/QueryGroup/index.tsx
+++ b/ui/src/components/QueryGroup/index.tsx
@@ -5,6 +5,8 @@ import { useTranslation } from 'react-i18next';
import classNames from 'classnames';
+import { floppyNavigation } from '@/utils';
+
interface Props {
data;
i18nKeyPrefix: string;
@@ -39,10 +41,12 @@ const Index: FC<Props> = ({
};
const handleClick = (e, type) => {
- e.preventDefault();
const str = handleParams(type);
if (pathname) {
- navigate(`${pathname}${str}`);
+ if (floppyNavigation.shouldProcessLinkClick(e)) {
+ e.preventDefault();
+ navigate(`${pathname}${str}`);
+ }
} else {
setUrlSearchParams(str);
}
diff --git a/ui/src/pages/Users/Notifications/index.tsx b/ui/src/pages/Users/Notifications/index.tsx
index c96ead98..e903b4fb 100644
--- a/ui/src/pages/Users/Notifications/index.tsx
+++ b/ui/src/pages/Users/Notifications/index.tsx
@@ -10,6 +10,7 @@ import {
clearNotificationStatus,
readNotification,
} from '@/services';
+import { floppyNavigation } from '@/utils';
import Inbox from './components/Inbox';
import Achievements from './components/Achievements';
@@ -45,6 +46,9 @@ const Notifications = () => {
const navigate = useNavigate();
const handleTypeChange = (evt, val) => {
+ if (!floppyNavigation.shouldProcessLinkClick(evt)) {
+ return;
+ }
evt.preventDefault();
if (type === val) {
return;