mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
refactor: use handleLinkClick from RA's utils (#5632)
This commit is contained in:
parent
743505fbc0
commit
f8fbe4ba22
6
.changeset/modern-carrots-run.md
Normal file
6
.changeset/modern-carrots-run.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@heroui/pagination": patch
|
||||
"@heroui/use-aria-link": patch
|
||||
---
|
||||
|
||||
refactor: use handleLinkClick from RA's utils
|
||||
@ -4,7 +4,7 @@ import type {LinkDOMProps, PressEvent} from "@react-types/shared";
|
||||
import type {PaginationItemValue} from "@heroui/use-pagination";
|
||||
|
||||
import {useMemo} from "react";
|
||||
import {shouldClientNavigate, useRouter} from "@react-aria/utils";
|
||||
import {handleLinkClick, useRouter} from "@react-aria/utils";
|
||||
import {clsx, dataAttr, chain, mergeProps} from "@heroui/shared-utils";
|
||||
import {filterDOMProps, useDOMRef} from "@heroui/react-utils";
|
||||
import {useHover, usePress} from "@react-aria/interactions";
|
||||
@ -109,20 +109,7 @@ export function usePaginationItem(props: UsePaginationItemProps) {
|
||||
className: clsx(className, props.className),
|
||||
onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
chain(pressProps?.onClick, onClick)(e);
|
||||
|
||||
// If a custom router is provided, prevent default and forward if this link should client navigate.
|
||||
if (
|
||||
!router.isNative &&
|
||||
e.currentTarget instanceof HTMLAnchorElement &&
|
||||
e.currentTarget.href &&
|
||||
// If props are applied to a router Link component, it may have already prevented default.
|
||||
!e.isDefaultPrevented() &&
|
||||
shouldClientNavigate(e.currentTarget, e) &&
|
||||
props.href
|
||||
) {
|
||||
e.preventDefault();
|
||||
router.open(e.currentTarget, e, props.href, props.routerOptions);
|
||||
}
|
||||
handleLinkClick(e, router, props.href, props.routerOptions);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -6,8 +6,8 @@ import {
|
||||
filterDOMProps,
|
||||
mergeProps,
|
||||
useRouter,
|
||||
shouldClientNavigate,
|
||||
useLinkProps,
|
||||
handleLinkClick,
|
||||
} from "@react-aria/utils";
|
||||
import {useFocusable} from "@react-aria/focus";
|
||||
import {usePress} from "@react-aria/interactions";
|
||||
@ -79,20 +79,7 @@ export function useAriaLink(props: AriaLinkOptions, ref: RefObject<FocusableElem
|
||||
"aria-current": props["aria-current"],
|
||||
onClick: (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
pressProps.onClick?.(e);
|
||||
|
||||
// If a custom router is provided, prevent default and forward if this link should client navigate.
|
||||
if (
|
||||
!router.isNative &&
|
||||
e.currentTarget instanceof HTMLAnchorElement &&
|
||||
e.currentTarget.href &&
|
||||
// If props are applied to a router Link component, it may have already prevented default.
|
||||
!e.isDefaultPrevented() &&
|
||||
shouldClientNavigate(e.currentTarget, e) &&
|
||||
props.href
|
||||
) {
|
||||
e.preventDefault();
|
||||
router.open(e.currentTarget, e, props.href, props.routerOptions);
|
||||
}
|
||||
handleLinkClick(e, router, props.href, props.routerOptions);
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user