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

MOON-116: Add animation on opening/closing accordion #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ffffffelix
Copy link
Collaborator

JIRA

https://jira.jahia.org/browse/MOON-116

Description

  • Add animation

const open = context.currentItem === id;

const handleClick = (e, open) => {
onClick(e, !open);
context.onSetOpenedItem(id);
};

useEffect(() => {
setCssExpanded({[styles.accordionItem_opened]: open});
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the need of a state here - why don't we use directly open ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's to trigger the animation after the render. We had some user feedback than they don't understand there is some accordion at the bottom of the page. We think to animate the opening of the accordion can improve this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it's only for the first render, if the accordion item is directly opened ? This has no impact when opening/closing the accordion after its first render ?

@@ -95,3 +98,18 @@ $accordionHeader_height: 48px;
background-color: var(--color-dark60);
}
}

// Animation
.accordionItem_opened {
Copy link
Contributor

Choose a reason for hiding this comment

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

please follow conventions for modifiers - .accordionItem.opened ( .accordion { &.opened {} }

@@ -7,28 +7,33 @@ import {AccordionContext} from '~/components/Accordion/Accordion.context';

export const AccordionItem = ({id, label, icon, onClick, children, className, ...props}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add callbacks for transition handling - onItemOpening / onItemOpened on Accordion before and after transition , also check what to do with onSetOpenedItem (currently called before transition)

Comment on lines +18 to +22
useEffect(() => {
setCssExpanded({[styles.accordionItem_opened]: open});
},
[open]);

Copy link
Contributor

Choose a reason for hiding this comment

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

If only for the first render I would suggest something like that :

Suggested change
useEffect(() => {
setCssExpanded({[styles.accordionItem_opened]: open});
},
[open]);
const [initialized, setInitialized] = useState(false);
useEffect(() => {
setInitialized(true)
}, []);
const isExpanded = open && initialized

And replace the cssExpanded with just {[styles.expanded]: isExpanded}

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