From 8d55d926569cd8bd6ea76f562ca133a22c1cd47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=D3=84=D5=A1?= Date: Thu, 6 Feb 2025 05:11:08 +0800 Subject: [PATCH] fix: deprecation warning triggered by internal onClick (#4557) * fix(use-aria-link): onClick deprecation warning * fix(use-aria-button): onClick deprecation warning * feat(changeset): add changeset * fix(use-aria-button): incorrect prop name * chore(changeset): update package name --- .changeset/stale-moose-hear.md | 6 ++++++ packages/hooks/use-aria-button/src/index.ts | 12 +++++++++++- packages/hooks/use-aria-link/src/index.ts | 12 +++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/stale-moose-hear.md diff --git a/.changeset/stale-moose-hear.md b/.changeset/stale-moose-hear.md new file mode 100644 index 0000000000..b885593d9f --- /dev/null +++ b/.changeset/stale-moose-hear.md @@ -0,0 +1,6 @@ +--- +"@heroui/use-aria-button": patch +"@heroui/use-aria-link": patch +--- + +avoid showing onClick deprecation warning for internal onClick (#4549, #4546) diff --git a/packages/hooks/use-aria-button/src/index.ts b/packages/hooks/use-aria-button/src/index.ts index 374b7b38f4..3a11499ce3 100644 --- a/packages/hooks/use-aria-button/src/index.ts +++ b/packages/hooks/use-aria-button/src/index.ts @@ -19,6 +19,8 @@ import {usePress} from "@react-aria/interactions"; export type AriaButtonProps = BaseAriaButtonProps & { /** Whether text selection should be enabled on the pressable element. */ allowTextSelectionOnPress?: boolean; + /** The role of the button element. */ + role?: string; }; export interface ButtonAria { @@ -81,6 +83,7 @@ export function useAriaButton( rel, type = "button", allowTextSelectionOnPress, + role, } = props; let additionalProps; @@ -104,7 +107,14 @@ export function useAriaButton( let isMobile = isIOS() || isAndroid(); - if (deprecatedOnClick && typeof deprecatedOnClick === "function") { + if ( + deprecatedOnClick && + typeof deprecatedOnClick === "function" && + // bypass since onClick is passed from internally + role !== "link" && + // bypass since onClick is passed from useDisclosure's `getButtonProps` internally + !(props.hasOwnProperty("aria-expanded") && props.hasOwnProperty("aria-controls")) + ) { warn( "onClick is deprecated, please use onPress instead. See: https://github.com/heroui-inc/heroui/issues/4292", "useButton", diff --git a/packages/hooks/use-aria-link/src/index.ts b/packages/hooks/use-aria-link/src/index.ts index 2d862bd6f1..8bcf86442f 100644 --- a/packages/hooks/use-aria-link/src/index.ts +++ b/packages/hooks/use-aria-link/src/index.ts @@ -21,6 +21,8 @@ export interface AriaLinkOptions extends AriaLinkProps { isDisabled?: boolean; /** The role of the element */ role?: string; + /** The type of the element, e.g. 'button' */ + type?: string; /** * The HTML element used to render the link, e.g. 'a', or 'span'. * @default 'a' @@ -50,6 +52,7 @@ export function useAriaLink(props: AriaLinkOptions, ref: RefObject internally + type !== "button" && + // bypass since onClick is passed from