Skip to content

Commit

Permalink
handle collapse in accordion
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Dec 1, 2020
1 parent d3b4143 commit 1eb564a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/manage/Blocks/Accordion/AccordionEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default (props) => {

setActiveIndex(newIndex);
}
//handle accordion collapse behavior
React.useEffect(() => {
data.collapsed ? setActiveIndex(-1) : setActiveIndex(0);
}, [data.collapsed]);

return (
<Accordion fluid styled>
Expand Down
7 changes: 6 additions & 1 deletion src/components/manage/Blocks/Accordion/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const accordionBlockSchema = () => ({
{
id: 'style',
title: 'Style',
fields: ['title_size', 'right_arrows'],
fields: ['title_size', 'right_arrows', 'collapsed'],
},
],
properties: {
Expand All @@ -53,6 +53,11 @@ export const accordionBlockSchema = () => ({
type: 'boolean',
default: false,
},
collapsed: {
title: 'Collapsed',
type: 'boolean',
default: true,
},
},
required: ['title'],
});
7 changes: 6 additions & 1 deletion src/components/manage/Blocks/Accordion/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const View = (props) => {
const newIndex = activeIndex === index ? -1 : index;
setActiveIndex(newIndex);
}

React.useEffect(() => {
data.collapsed ? setActiveIndex(-1) : setActiveIndex(0);
}, [data.collapsed]);

return (
<div className="accordion-block">
{panels.map(([id, panel], index) => {
return accordionBlockHasValue(panel) ? (
<Accordion fluid styled key={id}>
<Accordion fluid styled key={id} exclusive={false}>
<React.Fragment>
<Accordion.Title
as={data.title_size}
Expand Down

0 comments on commit 1eb564a

Please sign in to comment.