mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
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:
parent
25cf3e2f0d
commit
8d55d92656
6
.changeset/stale-moose-hear.md
Normal file
6
.changeset/stale-moose-hear.md
Normal 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)
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user