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: forwardRef render functions not using ref #4099

Open
wants to merge 3 commits into
base: beta/release-next
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
11 changes: 11 additions & 0 deletions .changeset/sharp-years-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@nextui-org/dropdown": patch
"@nextui-org/listbox": patch
"@nextui-org/menu": patch
"@nextui-org/modal": patch
"@nextui-org/popover": patch
"@nextui-org/system": patch
"@nextui-org/system-rsc": patch
---

fix forwardRef render functions not using ref
4 changes: 2 additions & 2 deletions packages/components/dropdown/src/dropdown-trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";
import {PopoverTrigger} from "@nextui-org/popover";

import {useDropdownContext} from "./dropdown-context";
Expand All @@ -11,7 +11,7 @@ export interface DropdownTriggerProps {
* DropdownTrigger opens the popover's content. It must be an interactive element
* such as `button` or `a`.
*/
const DropdownTrigger = forwardRef<"button", DropdownTriggerProps>((props, _) => {
const DropdownTrigger = wrapForwardRefTypes<"button", DropdownTriggerProps>((props, _) => {
const {getMenuTriggerProps} = useDropdownContext();

const {children, ...otherProps} = props;
Expand Down
4 changes: 2 additions & 2 deletions packages/components/listbox/src/listbox-item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useMemo, ReactNode} from "react";
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";

import {UseListboxItemProps, useListboxItem} from "./use-listbox-item";
import {ListboxSelectedIcon} from "./listbox-selected-icon";
Expand All @@ -9,7 +9,7 @@ export interface ListboxItemProps<T extends object = object> extends UseListboxI
/**
* @internal
*/
const ListboxItem = forwardRef<"li", ListboxItemProps>((props, _) => {
const ListboxItem = wrapForwardRefTypes<"li", ListboxItemProps>((props) => {
const {
Component,
rendered,
Expand Down
4 changes: 2 additions & 2 deletions packages/components/menu/src/menu-item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useMemo, ReactNode} from "react";
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";

import {UseMenuItemProps, useMenuItem} from "./use-menu-item";
import {MenuSelectedIcon} from "./menu-selected-icon";
Expand All @@ -9,7 +9,7 @@ export interface MenuItemProps<T extends object = object> extends UseMenuItemPro
/**
* @internal
*/
const MenuItem = forwardRef<"li", MenuItemProps>((props, _) => {
const MenuItem = wrapForwardRefTypes<"li", MenuItemProps>((props) => {
const {
Component,
slots,
Expand Down
4 changes: 2 additions & 2 deletions packages/components/modal/src/modal-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {AriaDialogProps} from "@react-aria/dialog";
import type {HTMLMotionProps} from "framer-motion";

import {cloneElement, isValidElement, ReactNode, useMemo, useCallback} from "react";
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";
import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-utils";
import {CloseIcon} from "@nextui-org/shared-icons";
Expand All @@ -23,7 +23,7 @@ export interface ModalContentProps extends AriaDialogProps, HTMLNextUIProps<"div

const domAnimation = () => import("@nextui-org/dom-animation").then((res) => res.default);

const ModalContent = forwardRef<"div", ModalContentProps, KeysToOmit>((props, _) => {
const ModalContent = wrapForwardRefTypes<"div", ModalContentProps, KeysToOmit>((props) => {
winchesHe marked this conversation as resolved.
Show resolved Hide resolved
const {as, children, role = "dialog", ...otherProps} = props;

const {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/popover/src/popover-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {AriaDialogProps} from "@react-aria/dialog";
import type {HTMLMotionProps} from "framer-motion";

import {DOMAttributes, ReactNode, useMemo, useRef} from "react";
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";
import {RemoveScroll} from "react-remove-scroll";
import {DismissButton} from "@react-aria/overlays";
import {TRANSITION_VARIANTS} from "@nextui-org/framer-utils";
Expand All @@ -21,7 +21,7 @@ export interface PopoverContentProps

const domAnimation = () => import("@nextui-org/dom-animation").then((res) => res.default);

const PopoverContent = forwardRef<"div", PopoverContentProps>((props, _) => {
const PopoverContent = wrapForwardRefTypes<"div", PopoverContentProps>((props) => {
const {as, children, className, ...otherProps} = props;

const {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/popover/src/popover-trigger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Children, cloneElement, useMemo} from "react";
import {forwardRef} from "@nextui-org/system";
import {wrapForwardRefTypes} from "@nextui-org/system";
import {pickChildren} from "@nextui-org/react-utils";
import {useAriaButton} from "@nextui-org/use-aria-button";
import {Button} from "@nextui-org/button";
Expand All @@ -15,7 +15,7 @@ export interface PopoverTriggerProps {
* PopoverTrigger opens the popover's content. It must be an interactive element
* such as `button` or `a`.
*/
const PopoverTrigger = forwardRef<"button", PopoverTriggerProps>((props, _) => {
const PopoverTrigger = wrapForwardRefTypes<"button", PopoverTriggerProps>((props) => {
const {triggerRef, getTriggerProps} = usePopoverContext();

const {children, ...otherProps} = props;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Visit [https://storybook.nextui.org](https://storybook.nextui.org/) to view the
Canary versions are available after every merge into `canary` branch. You can install the packages with the tag `canary` in npm to use the latest changes before the next production release.

- [Documentation](https://canary.nextui.org/docs)
- [Storybook](https://canary-storybook.nextui.org)
- [Storybook](https://canary-sb.nextui.org)

## Community

Expand Down
1 change: 1 addition & 0 deletions packages/core/system-rsc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
mapPropsVariants,
mapPropsVariantsWithCommon,
isNextUIEl,
wrapForwardRefTypes,
} from "./utils";

export {extendVariants} from "./extend-variants";
Expand Down
15 changes: 15 additions & 0 deletions packages/core/system-rsc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ export function forwardRef<
return baseForwardRef(component) as InternalForwardRefRenderFunction<Component, Props, OmitKeys>;
}

export function wrapForwardRefTypes<
Component extends As,
Props extends object,
OmitKeys extends keyof any = never,
>(
component: React.ForwardRefRenderFunction<
any,
RightJoinProps<PropsOf<Component>, Props> & {
as?: As;
}
>,
) {
return component as InternalForwardRefRenderFunction<Component, Props, OmitKeys>;
}

export const toIterator = (obj: any) => {
return {
...obj,
Expand Down
1 change: 1 addition & 0 deletions packages/core/system/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
mapPropsVariantsWithCommon,
isNextUIEl,
extendVariants,
wrapForwardRefTypes,
} from "@nextui-org/system-rsc";

export type {SupportedCalendars} from "./types";
Expand Down