Skip to content

fix(list): expand accordion with id 0 in a controlled AccordionGroup - #5145

Open
RaphaelFakhri wants to merge 1 commit into
callstack:mainfrom
RaphaelFakhri:fix/list-accordion-group-expanded-id-zero
Open

RaphaelFakhri wants to merge 1 commit into
callstack:mainfrom
RaphaelFakhri:fix/list-accordion-group-expanded-id-zero

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Motivation

A controlled List.AccordionGroup with expandedId={0} does not expand the accordion with id={0}. The group resolves the expanded ID with expandedIdProp || expandedId, so 0 falls back to the internal state, which a controlled group never updates. Indexes from .map are a common source of IDs, so the first accordion in such a list can never be opened.

This change uses ?? so only undefined falls back to the internal state. Uncontrolled groups behave as before.

Related issue

id={0} support was added in #3936 (fixing #3902), but the controlled expandedId path still treats 0 as missing. Fixes #5144

Screenshots / Videos

Not applicable. The change affects which accordion expands, not styling.

Test plan

  1. Render a controlled group:

    const [expandedId, setExpandedId] = React.useState<number | string>(0);
    
    <List.AccordionGroup expandedId={expandedId} onAccordionPress={setExpandedId}>
      <List.Accordion title="First" id={0}>
        <List.Item title="First item" />
      </List.Accordion>
      <List.Accordion title="Second" id={1}>
        <List.Item title="Second item" />
      </List.Accordion>
    </List.AccordionGroup>
  2. Confirm that "First" is expanded on mount.

  3. Press "Second", then press "First" again, and confirm that "First" expands.

Copilot AI balanced review requested due to automatic review settings October 25, 2026 06:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown

Found potential problems with the pull request:

  • The description is too long. Please keep it under 1000 characters.
  • Screenshot or video evidence is missing. Make sure to include one if it affects the UI.

This branch has not been deployed

No deployments
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.

List.AccordionGroup ignores a controlled expandedId of 0

2 participants