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 bugs on allow multiple on click #390

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

hadasfa
Copy link
Contributor

@hadasfa hadasfa commented Dec 14, 2021

Until now the allow multiple functionality was buggy because the on click functionality was not working as excepted

@@ -33,9 +33,12 @@ const Accordion = forwardRef(({ children: originalChildren, allowMultiple, defau
const onChildClick = useCallback(
itemIndex => {
if (allowMultiple) {
const newExpandedItems = expandedItems;
const newExpandedItems = [...expandedItems];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the first bug was that changing the state does not cause a render because the state was mutable

newExpandedItems.pop(itemIndex);
const index = newExpandedItems.indexOf(itemIndex);
if (index > -1) {
newExpandedItems.splice(index, 1);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the second bug was that clicking on already selected drawer caused removing the last opened drawer instead of the one we click on.

@hadasfa hadasfa merged commit bde2e52 into master Dec 15, 2021
@hadasfa hadasfa deleted the bug/hadas/accordion-allow-multiple branch December 15, 2021 07:47
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