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(react): fix issue where accordion would not pass through props correctly #713

Merged
merged 4 commits into from
Jul 27, 2022

Conversation

scurker
Copy link
Member

@scurker scurker commented Jul 26, 2022

This is needed for https://github.com/dequelabs/axe-extension/issues/2476 and addresses some outstanding issues.

@scurker scurker requested a review from a team as a code owner July 26, 2022 19:31
@github-actions
Copy link
Contributor

Preview branch generated at https://accordion-fixes.d1gko6en628vir.amplifyapp.com

schne324
schne324 previously approved these changes Jul 26, 2022
Comment on lines +93 to +95
open={open}
onToggle={onToggle}
animationTiming={animationTiming}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are already spreading {...panelElement.props}. Why not have these props be part of the panel's props (AccordionContentProps)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize that the AccordionProps extend from ExpandCollapsePanel, but since that wasn't actually implemented, I don't think it would be a breaking change to make AccordionContentProps extend from ExpandCollapsePanel instead

Copy link
Member Author

Choose a reason for hiding this comment

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

Because they're 2 different elements. The resulting HTML looks something like this:

<div class="Accordion">
  <button>...</button>
  <div class="ExpandCollapse__Panel">...</div>
</div>

The accordion props should apply to the .Accordion element. The panel props should apply to the .ExpandCollapse__Panel element. They need to be able to set html attributes independently of one another.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand. This just seems set up a bit weird. For example, if I set an id on the AccordionContent element like this (note accordion-content-id):

  return (
    <Accordion open={open} onToggle={() => setIsOpen(!open)}>
      <AccordionTrigger heading={{ level: 4 }}>{label}</AccordionTrigger>
      <AccordionContent id="accordion-content-id">Here is some content</AccordionContent>
    </Accordion>
  );

Then the rendered HTML has two elements with the same id, which is invalid HTML:

<div class="Accordion">
   <h4>...</h4>
   <div class="ExpandCollapse__panel" id="accordion-content-id">
      <div class="Accordion__panel" id="accordion-content-id">Here is some content</div>
   </div>
</div>

Similarly, if I set any other attributes, such as className on the AccordionContent component, those attributes will be set on both the ExpandCollapse__panel and Accordion__panel elements.

Although I realize my original suggestion is not the correct solution, I still feel like something needs to change here.

Copy link
Member Author

@scurker scurker Jul 26, 2022

Choose a reason for hiding this comment

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

That's a pre-existing issue, I went ahead and created #714. We should definitely fix it, but I'm not sure what the solution should be yet and I don't want it blocking things I'm currently working on.

@scurker scurker merged commit 9fd91f4 into develop Jul 27, 2022
@scurker scurker deleted the accordion-fixes branch July 27, 2022 13:47
@github-actions
Copy link
Contributor

Preview branch generated at https://accordion-fixes.d1gko6en628vir.amplifyapp.com

@scurker scurker mentioned this pull request Jul 29, 2022
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.

3 participants