Skip to content

Commit

Permalink
Merge pull request #707 from PEM-Humboldt/hotfix/2.0.3
Browse files Browse the repository at this point in the history
Set default accordion first time it has content
  • Loading branch information
erikasv authored Aug 12, 2022
2 parents 265b4bd + 2aedf9f commit 840e2b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "biotablero",
"version": "2.0.2",
"version": "2.0.3",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
31 changes: 22 additions & 9 deletions src/pages/search/Accordion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,31 @@ class Accordion extends React.Component {
componentDidMount() {
const { componentsArray } = this.props;
if (componentsArray.length > 0) {
let defaultTab = componentsArray.find(
(item) => !item.label.collapsed,
);
if (defaultTab) {
defaultTab = defaultTab.label.id;
} else {
defaultTab = null;
}
this.setState({ expanded: defaultTab });
this.setDefaultTab();
}
}

componentDidUpdate(prevProps) {
const { componentsArray: prevArray } = prevProps;
const { componentsArray } = this.props;
if (prevArray.length === 0 && componentsArray.length > 0) {
this.setDefaultTab();
}
}

setDefaultTab = () => {
const { componentsArray } = this.props;
let defaultTab = componentsArray.find(
(item) => !item.label.collapsed,
);
if (defaultTab) {
defaultTab = defaultTab.label.id;
} else {
defaultTab = null;
}
this.setState({ expanded: defaultTab });
}

render() {
const {
componentsArray,
Expand Down

0 comments on commit 840e2b7

Please sign in to comment.