Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deprecation warning triggered by internal onClick #4557

Open
wants to merge 5 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/nextui-org/nextui/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/nextui-org/nextui/issues/4292",
"useLink",
Expand Down
Loading