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: remove flicker in AccordionItem (#9818) #14776

Merged
merged 10 commits into from
Nov 30, 2023

Conversation

cesardlinx
Copy link
Contributor

Removes the flickering effect when using AccordionItem as a controlled component

Closes #9818

Changelog

Changed

  • I added a storybook example of the accordion as a controlled component

Removed

  • I removed an extra condition and a state that was the causing the problem

Testing / Reviewing

  • I run yarn test to verify that the Accordion related tests are still running

image

  • You can check the Accordion Controlled example in Storybook and verify that now the flickering is gone

Here you can see how it was working before:

Recording 2023-10-04 at 09 19 05

And this is how it is working now:

Recording 2023-10-04 at 09 22 40

@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for v11-carbon-react ready!

Name Link
🔨 Latest commit 36ec382
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/656756763c1fdc00085440d3
😎 Deploy Preview https://deploy-preview-14776--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Oct 4, 2023

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit b39e9f0
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/654c21fd57c1db0007418280
😎 Deploy Preview https://deploy-preview-14776--carbon-elements.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tw15egan
Copy link
Collaborator

tw15egan commented Oct 4, 2023

Still seeing a flicker when the Accordion is being closed - MacOS running Chrome latest

2023-10-04 11 16 00

@cesardlinx
Copy link
Contributor Author

cesardlinx commented Oct 4, 2023

Nice catch @tw15egan! You're absolutely right, I have updated the previous commit, this is how the tests are running

image

And this is how it's working now:

Recording 2023-10-04 at 11 58 28

@tw15egan
Copy link
Collaborator

tw15egan commented Oct 4, 2023

@cesardlinx unfortunately, this change removed the entire collapsing animation. I believe the animation itself may need to be reworked, and not rely on display: none since that seems to be causing the issue

2023-10-04 13 49 02

@cesardlinx
Copy link
Contributor Author

@tw15egan Yep! that's right. Let me elaborate more on why. Basically the main issue is that the collapsing animation is not actually "collapsing", instead it's "shrinking" as you can see here:

Recording 2023-10-04 at 14 19 02

So, the hacky trick that somebody used is to mixed the shrinking with the "display: none" in order to create the "collapsing" effect like this:

Recording 2023-10-04 at 14 20 29

And that's why you experience it like a small flickering when it collapses, because it's the combination of "shrinking" and then using "display: none". So what I did was to use only "display: none" in order to avoid the flickering.

@tw15egan
Copy link
Collaborator

tw15egan commented Oct 4, 2023

@cesardlinx the preferred solution would be to retain the animation and remove the flicker. The animation itself may need to be reworked.

@cesardlinx
Copy link
Contributor Author

@tw15egan I can rework the animation, but I don't think I can access it am I right?

@tw15egan
Copy link
Collaborator

tw15egan commented Oct 4, 2023

Great, if you are interested in trying to fix the animation, it is located in packages/styles/scss/components/accordion.scss

@cesardlinx
Copy link
Contributor Author

cesardlinx commented Oct 4, 2023

Nice! so cool, I thought that you were using an external package or something, that's great!! I'll fix it then :D

@cesardlinx
Copy link
Contributor Author

@tw15egan Animation reworked! This is how it works now:

Untitled

I'm getting some snapshot errors though as you can see here:

image

Should I update the snapshots? Please let me know

@cesardlinx
Copy link
Contributor Author

Hey @tw15egan any updates on this? were you able to verify how the animation is working now?

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

I don't see the flicker anymore but have a few concerns below.

packages/react/src/components/Accordion/AccordionItem.tsx Outdated Show resolved Hide resolved
packages/react/src/components/Accordion/AccordionItem.tsx Outdated Show resolved Hide resolved
packages/styles/scss/components/accordion/_accordion.scss Outdated Show resolved Hide resolved
packages/styles/scss/components/accordion/_accordion.scss Outdated Show resolved Hide resolved
@cesardlinx
Copy link
Contributor Author

Hey @tay1orjones. I've addressed all the issues you mentioned earlier. I would greatly appreciate your feedback when you have the time. Please take a look at my comments on changing the markup. I explain why we should add a wrapper around the accordion content.

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Thanks for making all those changes! I'm sorry for such a delay in reviewing. This is looking good, I have just two small comments after re-reviewing.

Comment on lines 141 to 147
const toggleElement = event.target;

let content = toggleElement.nextElementSibling;

// when toggle element is not the button
if (toggleElement.nodeName !== 'BUTTON') {
content = toggleElement.parentElement.nextElementSibling;
}
Copy link
Member

Choose a reason for hiding this comment

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

Gaining access to the content node this way feels brittle. Instead, could a ref be placed on the div containing the children, and then that contentRef.current.style be used in the maxBlockSize logic below?

content = toggleElement.parentElement.nextElementSibling;
}

if (content.style.maxBlockSize) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make more sense to use isOpen here?

@tay1orjones
Copy link
Member

Also snapshots need to be updated, just run yarn test -u from the project root and push up the changes. Thanks!

Copy link
Member

@tay1orjones tay1orjones left a comment

Choose a reason for hiding this comment

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

Thanks for addressing that feedback. I don't see the flicker in the storybook example. Removing the test story after a second approval and before merging would be good 👍

@cesardlinx
Copy link
Contributor Author

Awesome! Thank you @tay1orjones for all the feedback, I will remove the test story after second approval 👍

Copy link
Contributor

@andreancardona andreancardona left a comment

Choose a reason for hiding this comment

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

looks good! @cesardlinx

@cesardlinx
Copy link
Contributor Author

Thank you @andreancardona I have removed the test story as @tay1orjones suggested 🙂

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 28, 2023
@tay1orjones tay1orjones added this pull request to the merge queue Nov 30, 2023
Merged via the queue into carbon-design-system:main with commit 448c0ef Nov 30, 2023
20 checks passed
@carbon-automation
Copy link
Contributor

Hey there! v11.44.0 was just released that references this issue/PR.

danoro96 pushed a commit to danoro96/carbon that referenced this pull request Jan 18, 2024
…bon-design-system#14776)

* fix: remove flicker in AccordionItem (carbon-design-system#9818)

Removes the flickering effect when using AccordionItem as a controlled
component

* fix: rework accordion component animation (carbon-design-system#9818)

* refactor: use ref hook for accordion content

* test: update accordion component snapshots

* docs: fix extra missing curly brace in .all-contributorsrc

* docs: remove accordion controlled test story

---------

Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
Co-authored-by: Alison Joseph <alison.joseph@us.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Flicker in AccordionItem children
5 participants