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(accordion): add missing ref to AccordionItem #3718

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 packages/components/accordion/__tests__/accordion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,15 @@ describe("Accordion", () => {

expect(getByRole("separator")).toHaveClass("bg-rose-500");
});

it("AccordionItem ref should be forwarded", () => {
const ref = React.createRef<HTMLButtonElement>();

render(
<Accordion>
<AccordionItem ref={ref}>Accordion Item</AccordionItem>
</Accordion>,
);
expect(ref.current).not.toBeNull();
});
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
});
1 change: 1 addition & 0 deletions packages/components/accordion/src/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const AccordionGroup = forwardRef<"div", AccordionProps>((props, ref) => {
return (
<Fragment key={item.key}>
<AccordionItem
ref={(props.children[index] || props.children).ref}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please explain both case

item={item}
variant={props.variant}
onFocusChange={handleFocusChanged}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import {As} from "@nextui-org/system";
import {ItemProps, BaseItem} from "@nextui-org/aria-utils";
import {FocusableProps, PressEvents} from "@react-types/shared";
import {ReactNode, MouseEventHandler} from "react";
import {ReactNode, MouseEventHandler, Ref} from "react";
import {HTMLMotionProps} from "framer-motion";

export type AccordionItemIndicatorProps = {
Expand Down Expand Up @@ -94,7 +94,8 @@ export interface Props<T extends object = {}>
HeadingComponent?: As;
}

export type AccordionItemBaseProps<T extends object = {}> = Props<T> & AccordionItemVariantProps;
export type AccordionItemBaseProps<T extends object = {}> = Props<T> &
AccordionItemVariantProps & {ref?: Ref<HTMLButtonElement>};
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref should be from Props


const AccordionItemBase = BaseItem as (props: AccordionItemBaseProps) => JSX.Element;

Expand Down