Skip to content

bug: checkbox inside an accordion content causes the accordion onIonChange event to fire #27724

Closed

Description

@corysmc

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

If I have a checkbox inside of an ion-accordion element, when the checkbox is checked the accordion also fires a change event - which in my case - closes the accordion.

Expected Behavior

Events inside the accordion content should not cause the accordion change event to fire.

Steps to Reproduce

  1. Add an ion-checkbox to the inside of the content of an ion-accordion
  2. Add an event listener to the accordion-group
  3. Check the box - notice the accordion group event fires

Workaround - add event.stopPropagation to the checkbox event listener

Code Reproduction URL

https://stackblitz.com/edit/g4jdvt?file=src%2Fmain.tsx

Ionic Info

N/A

Additional Information

#26771

The solution to this bug is for a checkbox inside the accordion header - so the fix makes sense. However, I would not expect an item inside the content to toggle the accordion closed.

Activity

  1. self-assigned this
    on Jun 30, 2023
  2. liamdebeasi commented on Jun 30, 2023

    @liamdebeasi
    Contributor

    Thanks for the report. I can reproduce this behavior, but Ionic is working as intended here.

    ionChange events bubble, so when you add onIonChange to ion-accordion-group, you are essentially doing accordionGroupEl.addEventListener('ionChange', () => { ... });. In this case, the ionChange event from ion-checkbox is bubbling up to the ion-accordion-group, causing your ionChange callback on ion-accordion-group to fire.

    You can check ev.target.tagName === 'ION-ACCORDION-GROUP' to verify that the ionChange event you are seeing is indeed coming from ion-accordion-group and not a child element.

  3. added
    needs: reply
    on Jun 30, 2023
  4. removed their assignment
    on Jun 30, 2023
  5. corysmc commented on Jul 3, 2023

    @corysmc
    ContributorAuthor

    Thanks for the explanation 👍

  6. added and removed
    needs: reply
    on Jul 3, 2023
  7. ionitron-bot commented on Aug 2, 2023

    @ionitron-bot

    Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

  8. locked and limited conversation to collaborators on Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions