Browse Source

support update of props.initiallyCollapsed in CollapsableControls

Alexander Rose 5 years ago
parent
commit
ecaab51315
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/mol-plugin-ui/base.tsx

+ 7 - 1
src/mol-plugin-ui/base.tsx

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -83,6 +83,12 @@ export abstract class CollapsableControls<P = {}, S = {}, SS = {}> extends Plugi
         this.setState({ isCollapsed: !this.state.isCollapsed } as (S & CollapsableState))
     }
 
+    componentDidUpdate(prevProps: P & CollapsableProps) {
+        if(this.props.initiallyCollapsed !== undefined && prevProps.initiallyCollapsed !== this.props.initiallyCollapsed) {
+            this.setState({ isCollapsed: this.props.initiallyCollapsed as any });
+        }
+    }
+
     protected abstract defaultState(): (S & CollapsableState)
     protected abstract renderControls(): JSX.Element | null