You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-11-20 12:02:22 +03:00
frontend: make the link behavior better
It now ignores clicks with modifiers and has the right full href
This commit is contained in:
@@ -149,13 +149,21 @@ const Router: React.FC = () => (
|
|||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Filter out clicks with modifiers or that have been prevented
|
||||||
|
const shouldHandleClick = (e: React.MouseEvent): boolean =>
|
||||||
|
!e.defaultPrevented &&
|
||||||
|
e.button === 0 &&
|
||||||
|
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
||||||
|
|
||||||
export const Link: React.FC<
|
export const Link: React.FC<
|
||||||
{
|
{
|
||||||
route: Route;
|
route: Route;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
} & React.HTMLProps<HTMLAnchorElement>
|
} & React.HTMLProps<HTMLAnchorElement>
|
||||||
> = ({ route, children, ...props }) => {
|
> = ({ route, children, ...props }) => {
|
||||||
|
const config = useAtomValue(appConfigAtom);
|
||||||
const path = routeToPath(route);
|
const path = routeToPath(route);
|
||||||
|
const fullUrl = config.root + path;
|
||||||
const setRoute = useSetAtom(routeAtom);
|
const setRoute = useSetAtom(routeAtom);
|
||||||
|
|
||||||
// TODO: we should probably have more user control over this
|
// TODO: we should probably have more user control over this
|
||||||
@@ -163,8 +171,13 @@ export const Link: React.FC<
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
href={path}
|
href={fullUrl}
|
||||||
onClick={(e: React.MouseEvent): void => {
|
onClick={(e: React.MouseEvent): void => {
|
||||||
|
// Only handle left clicks without modifiers
|
||||||
|
if (!shouldHandleClick(e)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
setRoute(route);
|
setRoute(route);
|
||||||
|
|||||||
Reference in New Issue
Block a user