Skip to content

Commit

Permalink
feat: add contitions to use linking feature if the field 'Allow linki…
Browse files Browse the repository at this point in the history
…ng' is selected
  • Loading branch information
MihaelaCretu11 committed Jun 30, 2023
1 parent b7d28b4 commit 76e624d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
15 changes: 15 additions & 0 deletions src/components/manage/Blocks/Accordion/Schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ const messages = defineMessages({
id: 'Allow multiple panels open at a time',
defaultMessage: 'Allow multiple panels open at a time',
},
allow_linking: {
id: 'Allow linking',
defaultMessage: 'Allow linking',
},
allow_linking_description: {
id: 'Allow linking to the last accordion item selected',
defaultMessage: 'Allow linking to the last accordion item selected',
},
Theme: {
id: 'Theme',
defaultMessage: 'Theme',
Expand Down Expand Up @@ -99,6 +107,7 @@ export const AccordionBlockSchema = ({ intl }) => ({
'right_arrows',
'collapsed',
'non_exclusive',
'allow_linking',
],
},
],
Expand Down Expand Up @@ -142,6 +151,12 @@ export const AccordionBlockSchema = ({ intl }) => ({
type: 'boolean',
default: true,
},
allow_linking: {
title: intl.formatMessage(messages.allow_linking),
description: intl.formatMessage(messages.allow_linking_description),
type: 'boolean',
default: true,
},
},
required: ['title'],
});
Expand Down
20 changes: 15 additions & 5 deletions src/components/manage/Blocks/Accordion/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const View = (props) => {
};

const scrollToElement = () => {
if (!!activePanels) {
if (!!activePanels && data.allow_linking && !!activePanels[0].length) {
let element = document.getElementById(
activePanels[activePanels.length - 1],
);
Expand All @@ -94,11 +94,21 @@ const View = (props) => {
}, []);

React.useEffect(() => {
return data.collapsed
? activePanels && setActivePanel(activePanels || [])
: setActivePanel([firstIdFromPanels, ...(activePanels || [])]);
if (data.allow_linking) {
if (data.collapsed) {
setActivePanel(activePanels || []);
} else {
if (!!activePanels && !!activePanels[0].length) {
setActivePanel(activePanels || []);
} else {
setActivePanel([firstIdFromPanels, ...(activePanels || [])]);
}
}
} else {
setActiveIndex(data.collapsed ? [] : [0]);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [data.collapsed]);
}, [data.collapsed, data.allow_linking]);

return (
<div className="accordion-block">
Expand Down

0 comments on commit 76e624d

Please sign in to comment.