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

Open all accordion'd content in InlineForm by default, allow arbitrarily close any number of them #4178

Merged
merged 10 commits into from
May 11, 2023
2 changes: 0 additions & 2 deletions cypress/tests/core/blocks/blocks-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('Search Block Tests', () => {
cy.get('.blocks-chooser .common').contains('Search').click();

// Add search query criteria
cy.get('#blockform-fieldset-searchquery').click();
cy.get('#default-query-0-query .react-select__value-container').click();
cy.get('#default-query-0-query .react-select__option')
.contains('Type')
Expand Down Expand Up @@ -77,7 +76,6 @@ describe('Search Block Tests', () => {
.click();

// Add checkbox facet
cy.get('#blockform-fieldset-facets > .title').click();
cy.get('.add-item-button-wrapper > button').click();
cy.get('#field-field-1-facets-0 .react-select__value-container').click();
cy.get('.react-select__option').contains('Type').click();
Expand Down
1 change: 1 addition & 0 deletions news/4178.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Open all accordion'd content in InlineForm by default, allow arbitrarily close any number of them. @sneridagh
36 changes: 27 additions & 9 deletions src/components/manage/Form/InlineForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { Accordion, Segment, Message } from 'semantic-ui-react';
import { defineMessages, injectIntl } from 'react-intl';
import AnimateHeight from 'react-animate-height';
import { keys, map, isEqual } from 'lodash';

import {
insertInArray,
removeFromArray,
} from '@plone/volto/helpers/Utils/Utils';
import { Field, Icon } from '@plone/volto/components';
import { applySchemaDefaults } from '@plone/volto/helpers';

Expand Down Expand Up @@ -70,12 +73,27 @@ const InlineForm = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const [currentActiveFieldset, setCurrentActiveFieldset] = React.useState(0);
const [currentActiveFieldset, setCurrentActiveFieldset] = React.useState([
...Array.from(Array(other.length).keys()),
]);
function handleCurrentActiveFieldset(e, blockProps) {
const { index } = blockProps;
const newIndex = currentActiveFieldset === index ? -1 : index;

setCurrentActiveFieldset(newIndex);
if (currentActiveFieldset.includes(index)) {
setCurrentActiveFieldset(
removeFromArray(
currentActiveFieldset,
currentActiveFieldset.indexOf(index),
),
);
} else {
setCurrentActiveFieldset(
insertInArray(
currentActiveFieldset,
index,
currentActiveFieldset.length + 1,
),
);
}
}

return (
Expand Down Expand Up @@ -136,22 +154,22 @@ const InlineForm = (props) => {
<Accordion fluid styled className="form" key={fieldset.id}>
<div key={fieldset.id} id={`blockform-fieldset-${fieldset.id}`}>
<Accordion.Title
active={currentActiveFieldset === index}
active={currentActiveFieldset.includes(index)}
index={index}
onClick={handleCurrentActiveFieldset}
>
{fieldset.title && <>{fieldset.title}</>}
{currentActiveFieldset === index ? (
{currentActiveFieldset.includes(index) ? (
<Icon name={upSVG} size="20px" />
) : (
<Icon name={downSVG} size="20px" />
)}
</Accordion.Title>
<Accordion.Content active={currentActiveFieldset === index}>
<Accordion.Content active={currentActiveFieldset.includes(index)}>
<AnimateHeight
animateOpacity
duration={500}
height={currentActiveFieldset === index ? 'auto' : 0}
height={currentActiveFieldset.includes(index) ? 'auto' : 0}
>
<Segment className="attached">
{map(fieldset.fields, (field) => (
Expand Down