fix(popover): isDisabled prop on a DOM element (#2741)

* fix(popover): isDisabled prop on a DOM element

* refactor(popover): filter non-react props

* fix(dropdown): tests

---------

Co-authored-by: Junior Garcia <jrgarciadev@gmail.com>
This commit is contained in:
աӄա 2024-04-18 10:50:42 +08:00 committed by GitHub
parent 6b56e43a35
commit f89356691c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 9 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/popover": patch
---
Fixes isDisabled prop on a DOM element

View File

@ -109,6 +109,7 @@ describe("Dropdown", () => {
items={section.children}
title={section.title}
>
{/* @ts-ignore */}
{(item: any) => <DropdownItem key={item.key}>{item.name}</DropdownItem>}
</DropdownSection>
)}

View File

@ -1,6 +1,6 @@
import React, {Children, cloneElement, useMemo} from "react";
import {forwardRef, isNextUIEl} from "@nextui-org/system";
import {pickChildren, filterDOMProps} from "@nextui-org/react-utils";
import {filterDOMProps, 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,18 +42,11 @@ const PopoverTrigger = forwardRef<"button", PopoverTriggerProps>((props, _) => {
return triggerChildren?.[0] !== undefined;
}, [triggerChildren]);
const isDisabled = !!restProps?.isDisabled;
const isNextUIElement = isNextUIEl(child);
return cloneElement(
child,
mergeProps(
// if we add `isDisabled` prop to DOM elements,
// react will fail to recognize it on a DOM element,
// hence, apply filterDOMProps for such case
filterDOMProps(restProps, {
enabled: isDisabled && !isNextUIElement,
enabled: !isNextUIEl(child),
}),
hasNextUIButton ? {onPress} : buttonProps,
),