Skip to content

Commit

Permalink
fix: deprecation warning triggered by internal onClick (#4557)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wingkwong authored Feb 5, 2025
1 parent 25cf3e2 commit 8d55d92
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-moose-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@heroui/use-aria-button": patch
"@heroui/use-aria-link": patch
---

avoid showing onClick deprecation warning for internal onClick (#4549, #4546)
12 changes: 11 additions & 1 deletion packages/hooks/use-aria-button/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -81,6 +83,7 @@ export function useAriaButton(
rel,
type = "button",
allowTextSelectionOnPress,
role,
} = props;
let additionalProps;

Expand All @@ -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",
Expand Down
12 changes: 11 additions & 1 deletion packages/hooks/use-aria-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -50,6 +52,7 @@ export function useAriaLink(props: AriaLinkOptions, ref: RefObject<FocusableElem
onClick: deprecatedOnClick,
role,
isDisabled,
type,
...otherProps
} = props;

Expand All @@ -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",
Expand Down

0 comments on commit 8d55d92

Please sign in to comment.