Skip to content

fix(Accordion): defaultExpanded=false open#2736

Merged
aeksandla merged 1 commit into
mainfrom
aeksandla/fix-accordion
Jul 10, 2026
Merged

fix(Accordion): defaultExpanded=false open#2736
aeksandla merged 1 commit into
mainfrom
aeksandla/fix-accordion

Conversation

@aeksandla

@aeksandla aeksandla commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

fix for #2718

Summary by Sourcery

Ensure Accordion items configured with defaultExpanded=false behave correctly when toggled and when interacting with other items.

Bug Fixes:

  • Fix AccordionItem so items with defaultExpanded=false open when clicked.
  • Fix AccordionItem so items with defaultExpanded=false close when another item in the same Accordion is opened.

Tests:

  • Add tests covering AccordionItem behavior when defaultExpanded=false, including opening on click and closing when another item opens.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adjusts AccordionItem expansion logic so items with defaultExpanded=false behave as interactive, closable items, and adds tests to cover the new behavior, including interaction between multiple items.

File-Level Changes

Change Details Files
Fix AccordionItem expansion logic so defaultExpanded=false items can open and close correctly, including when other items are expanded.
  • Introduce disclosureExpanded variable to determine the value passed to the underlying Disclosure component based on controlled/expanded and defaultExpanded states.
  • Change the expanded prop passed to Disclosure from a simple defaultExpanded check to use the new disclosureExpanded logic.
  • Refine useAccordionItemState to treat only defaultExpanded===true as a special default state, renaming hasDefaultState to hasDefaultExpanded and updating memoization dependencies.
  • Update the expansion computation so uncontrolled items with defaultExpanded===true start collapsed, and clicking them updates the accordion state only when they are not in that special default-expanded-on-mount mode.
src/components/Accordion/AccordionItem/AccordionItem.tsx
Add tests verifying AccordionItem behavior when defaultExpanded=false, including user interactions and interaction with other items.
  • Add a test that asserts an AccordionItem with defaultExpanded=false starts collapsed and becomes expanded when its summary is clicked.
  • Add a test that asserts an AccordionItem with defaultExpanded=false closes when another item in the same Accordion is opened, and that the newly opened item becomes visible.
src/components/Accordion/__tests__/Accordion.test.tsx

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gravity-ui

gravity-ui Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Preview is ready.

@gravity-ui

gravity-ui Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🎭 Component Tests Report is ready.

@aeksandla aeksandla marked this pull request as ready for review July 9, 2026 15:58
@aeksandla aeksandla requested a review from KostyaAvtushko as a code owner July 9, 2026 15:58

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new disclosureExpanded ternary (expanded !== undefined || defaultExpanded !== true ? isExpanded : undefined) is a bit hard to parse; consider refactoring into clearer boolean helpers or branching to make the controlled vs defaultExpanded behavior explicit.
  • Renaming hasDefaultState to hasDefaultExpanded and changing the semantics to defaultExpanded === true alters the meaning subtly; it may be clearer to keep a neutral name and explicitly handle true, false, and undefined cases to avoid future confusion around the default behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `disclosureExpanded` ternary (`expanded !== undefined || defaultExpanded !== true ? isExpanded : undefined`) is a bit hard to parse; consider refactoring into clearer boolean helpers or branching to make the controlled vs defaultExpanded behavior explicit.
- Renaming `hasDefaultState` to `hasDefaultExpanded` and changing the semantics to `defaultExpanded === true` alters the meaning subtly; it may be clearer to keep a neutral name and explicitly handle `true`, `false`, and `undefined` cases to avoid future confusion around the default behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@aeksandla aeksandla merged commit 6377bf1 into main Jul 10, 2026
7 of 8 checks passed
@aeksandla aeksandla deleted the aeksandla/fix-accordion branch July 10, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants