-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: canary
Are you sure you want to change the base?
fix(accordion): add missing ref to AccordionItem #3718
Conversation
🦋 Changeset detectedLatest commit: 97ddc6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (3)
- packages/components/accordion/tests/accordion.test.tsx (1 hunks)
- packages/components/accordion/src/accordion.tsx (1 hunks)
- packages/components/accordion/src/base/accordion-item-base.tsx (2 hunks)
Additional context used
Biome
packages/components/accordion/src/base/accordion-item-base.tsx
[error] 97-97: Don't use '{}' as a type.
Prefer explicitly define the object shape. '{}' means "any non-nullable value".
(lint/complexity/noBannedTypes)
Additional comments not posted (2)
packages/components/accordion/src/accordion.tsx (1)
39-39
: Refactor the ref prop handling for better robustness.The current implementation of forwarding the
ref
prop toAccordionItem
uses the expression(props.children[index] || props.children).ref
. This approach assumes thatchildren
will always have aref
property and can handle being accessed by index, which might not always be the case.Consider using React's
React.Children
API to more safely interact withchildren
. This API provides utilities likeReact.Children.map
that handle different types of children (single child, no children, or an array of children) more gracefully.Here's a suggested refactor:
- ref={(props.children[index] || props.children).ref} + ref={React.Children.map(props.children, (child, idx) => idx === index ? child.ref : null)}This change ensures that the
ref
is only applied to the correct child and handles various forms ofchildren
more safely.packages/components/accordion/src/base/accordion-item-base.tsx (1)
10-10
: Approved import statement forRef
.The addition of
Ref
from React is necessary for implementing the newref
prop functionality in theAccordionItem
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please include changeset
oops, done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Files selected for processing (1)
- .changeset/neat-trains-sit.md (1 hunks)
Files skipped from review due to trivial changes (1)
- .changeset/neat-trains-sit.md
@@ -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>}; |
There was a problem hiding this comment.
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
@@ -36,6 +36,7 @@ const AccordionGroup = forwardRef<"div", AccordionProps>((props, ref) => { | |||
return ( | |||
<Fragment key={item.key}> | |||
<AccordionItem | |||
ref={(props.children[index] || props.children).ref} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please explain both case
"@nextui-org/accordion": patch | ||
--- | ||
|
||
Added ref to AccordionItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also include issue number
Added ref to AccordionItem (#3498)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also check with #3498 (comment)
Closes #3498
📝 Description
Fix issue where AccordionItem ref is not properly implemented, add typescript typing
⛳️ Current behavior (updates)
AccordionItem does not currently support ref.
🚀 New behavior
AccordionItem now implements ref.
💣 Is this a breaking change (Yes/No):
No
📝 Additional Information
Summary by CodeRabbit
New Features
AccordionItem
component to support ref forwarding, improving focus management and interactivity.AccordionItem
within the accordion package for better organization and accessibility.Tests
AccordionItem
, increasing test coverage and reliability.