fix(popover): ref not beign passed

This commit is contained in:
Junior Garcia 2024-04-18 08:48:42 -03:00
parent 69f713cb05
commit 9e5dd8ce37
2 changed files with 14 additions and 10 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/popover": patch
---
Fix ref not beign passed

View File

@ -1,6 +1,6 @@
import React, {Children, cloneElement, useMemo} from "react";
import {forwardRef, isNextUIEl} from "@nextui-org/system";
import {filterDOMProps, pickChildren} from "@nextui-org/react-utils";
import {pickChildren} from "@nextui-org/react-utils";
import {useAriaButton} from "@nextui-org/use-aria-button";
import {Button} from "@nextui-org/button";
import {mergeProps} from "@react-aria/utils";
@ -42,15 +42,14 @@ const PopoverTrigger = forwardRef<"button", PopoverTriggerProps>((props, _) => {
return triggerChildren?.[0] !== undefined;
}, [triggerChildren]);
return cloneElement(
child,
mergeProps(
filterDOMProps(restProps, {
enabled: !isNextUIEl(child),
}),
hasNextUIButton ? {onPress} : buttonProps,
),
);
const isNextUIElement = isNextUIEl(child);
// `isDisabled` is added in `getMenuTriggerProps()` in `use-dropdown.ts`.
// if we include `isDisabled` prop in a DOM element, react will fail to recognize it on a DOM element.
// hence, apply filterDOMProps for such case
if (!isNextUIElement) delete restProps["isDisabled"];
return cloneElement(child, mergeProps(restProps, hasNextUIButton ? {onPress} : buttonProps));
});
PopoverTrigger.displayName = "NextUI.PopoverTrigger";