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
This commit is contained in:
աӄա 2025-02-06 05:11:08 +08:00 committed by GitHub
parent 25cf3e2f0d
commit 8d55d92656
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
"@heroui/use-aria-button": patch
"@heroui/use-aria-link": patch
---
avoid showing onClick deprecation warning for internal onClick (#4549, #4546)

View File

@ -19,6 +19,8 @@ import {usePress} from "@react-aria/interactions";
export type AriaButtonProps<T extends ElementType = "button"> = BaseAriaButtonProps<T> & {
/** Whether text selection should be enabled on the pressable element. */
allowTextSelectionOnPress?: boolean;
/** The role of the button element. */
role?: string;
};
export interface ButtonAria<T> {
@ -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 <Link as={Button} /> 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",

View File

@ -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<FocusableElem
onClick: deprecatedOnClick,
role,
isDisabled,
type,
...otherProps
} = props;
@ -64,7 +67,14 @@ export function useAriaLink(props: AriaLinkOptions, ref: RefObject<FocusableElem
let isMobile = isIOS() || isAndroid();
if (deprecatedOnClick && typeof deprecatedOnClick === "function" && role !== "button") {
if (
deprecatedOnClick &&
typeof deprecatedOnClick === "function" &&
// bypass since onClick is passed from <Link as="button" /> internally
type !== "button" &&
// bypass since onClick is passed from <Button as={Link} /> internally
role !== "button"
) {
warn(
"onClick is deprecated, please use onPress instead. See: https://github.com/heroui-inc/heroui/issues/4292",
"useLink",