fix(Link): fix unknown event warning when passing onPress prop (#1135)

* fix(Link): fix warning unknown event when passing onPress prop

* add useCallback
This commit is contained in:
camcam 2023-05-28 08:23:23 +07:00 committed by GitHub
parent fa404913bd
commit 102387a004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ import {HTMLNextUIProps, mapPropsVariants, PropGetter} from "@nextui-org/system"
import {useDOMRef} from "@nextui-org/dom-utils";
import {useFocusRing} from "@react-aria/focus";
import {dataAttr, ReactRef} from "@nextui-org/shared-utils";
import {useMemo} from "react";
import {useMemo, useCallback} from "react";
import {mergeProps} from "@react-aria/utils";
interface Props extends HTMLNextUIProps<"a">, LinkVariantProps {
@ -46,6 +46,8 @@ export function useLink(originalProps: UseLinkProps) {
showAnchorIcon = false,
autoFocus = false,
className,
onPress,
onClick,
...otherProps
} = props;
@ -53,7 +55,7 @@ export function useLink(originalProps: UseLinkProps) {
const domRef = useDOMRef(ref);
const {linkProps} = useAriaLink({...otherProps, elementType: `${as}`}, domRef);
const {linkProps} = useAriaLink({...otherProps, onPress, onClick, elementType: `${as}`}, domRef);
const {isFocused, isFocusVisible, focusProps} = useFocusRing({
autoFocus,
@ -73,15 +75,15 @@ export function useLink(originalProps: UseLinkProps) {
[...Object.values(variantProps), className],
);
const getLinkProps: PropGetter = (props = {}) => {
const getLinkProps: PropGetter = useCallback(() => {
return {
ref: domRef,
className: classNames,
"data-focused": dataAttr(isFocused),
"data-focus-visible": dataAttr(isFocusVisible),
...mergeProps(focusProps, linkProps, otherProps, props),
};
...mergeProps(focusProps, linkProps, otherProps),
};
}, [classNames, isFocused, isFocusVisible, focusProps, linkProps, otherProps]);
return {Component, children, anchorIcon, showAnchorIcon, getLinkProps};
}