Skip to content

Commit b18b51b

Browse files
hip3rdemshy
andauthored
fix: //issues/6812 show code widget content if initially hidden (#7131)
Co-authored-by: Anze Demsar <[email protected]>
1 parent 0c68d20 commit b18b51b

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

packages/decap-cms-core/src/components/Editor/EditorControlPane/EditorControl.js

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class EditorControl extends React.Component {
147147
isFieldDuplicate: PropTypes.func,
148148
isFieldHidden: PropTypes.func,
149149
locale: PropTypes.string,
150+
isParentListCollapsed: PropTypes.bool,
150151
};
151152

152153
static defaultProps = {
@@ -210,6 +211,7 @@ class EditorControl extends React.Component {
210211
isFieldDuplicate,
211212
isFieldHidden,
212213
locale,
214+
isParentListCollapsed,
213215
} = this.props;
214216

215217
const widgetName = field.get('widget');
@@ -332,6 +334,7 @@ class EditorControl extends React.Component {
332334
isFieldHidden={isFieldHidden}
333335
isLoadingAsset={isLoadingAsset}
334336
locale={locale}
337+
isParentListCollapsed={isParentListCollapsed}
335338
/>
336339
{fieldHint && (
337340
<ControlHint active={isSelected || this.state.styleActive} error={hasErrors}>

packages/decap-cms-core/src/components/Editor/EditorControlPane/Widget.js

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default class Widget extends Component {
7272
isFieldDuplicate: PropTypes.func,
7373
isFieldHidden: PropTypes.func,
7474
locale: PropTypes.string,
75+
isParentListCollapsed: PropTypes.bool,
7576
};
7677

7778
shouldComponentUpdate(nextProps) {
@@ -298,6 +299,7 @@ export default class Widget extends Component {
298299
isFieldDuplicate,
299300
isFieldHidden,
300301
locale,
302+
isParentListCollapsed,
301303
} = this.props;
302304

303305
return React.createElement(controlComponent, {
@@ -350,6 +352,7 @@ export default class Widget extends Component {
350352
isFieldDuplicate,
351353
isFieldHidden,
352354
locale,
355+
isParentListCollapsed,
353356
});
354357
}
355358
}

packages/decap-cms-widget-code/src/CodeControl.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export default class CodeControl extends React.Component {
6868
forID: PropTypes.string.isRequired,
6969
classNameWrapper: PropTypes.string.isRequired,
7070
widget: PropTypes.object.isRequired,
71+
isParentListCollapsed: PropTypes.bool,
7172
};
7273

7374
keys = this.getKeys(this.props.field);
@@ -83,9 +84,16 @@ export default class CodeControl extends React.Component {
8384
lastKnownValue: this.valueIsMap() ? this.props.value?.get(this.keys.code) : this.props.value,
8485
};
8586

87+
visibility = {
88+
isInvisibleOnInit: this.props.isParentListCollapsed === true,
89+
isRefreshedAfterInvisible: false,
90+
};
91+
8692
shouldComponentUpdate(nextProps, nextState) {
8793
return (
88-
!isEqual(this.state, nextState) || this.props.classNameWrapper !== nextProps.classNameWrapper
94+
!isEqual(this.state, nextState) ||
95+
this.props.classNameWrapper !== nextProps.classNameWrapper ||
96+
(this.visibility.isInvisibleOnInit && !this.visibility.isRefreshedAfterInvisible)
8997
);
9098
}
9199

@@ -97,6 +105,14 @@ export default class CodeControl extends React.Component {
97105

98106
componentDidUpdate(prevProps, prevState) {
99107
this.updateCodeMirrorProps(prevState);
108+
// when initially hidden and then shown, codeMirror content is not visible
109+
if (
110+
this.visibility.isInvisibleOnInit &&
111+
!this.visibility.isRefreshedAfterInvisible &&
112+
!this.props.listCollapsed
113+
) {
114+
this.refreshCodeMirrorInstance();
115+
}
100116
}
101117

102118
updateCodeMirrorProps(prevState) {
@@ -107,6 +123,13 @@ export default class CodeControl extends React.Component {
107123
}
108124
}
109125

126+
refreshCodeMirrorInstance() {
127+
if (this.cm?.getWrapperElement().offsetHeight) {
128+
this.cm.refresh();
129+
this.visibility.isRefreshedAfterInvisible = true;
130+
}
131+
}
132+
110133
getLanguageByName = name => {
111134
return languages.find(lang => lang.name === name);
112135
};

packages/decap-cms-widget-object/src/ObjectControl.js

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default class ObjectControl extends React.Component {
4040
hasError: PropTypes.bool,
4141
t: PropTypes.func,
4242
locale: PropTypes.string,
43+
collapsed: PropTypes.bool,
4344
};
4445

4546
static defaultProps = {
@@ -87,6 +88,7 @@ export default class ObjectControl extends React.Component {
8788
isFieldDuplicate,
8889
isFieldHidden,
8990
locale,
91+
collapsed,
9092
} = this.props;
9193

9294
if (field.get('widget') === 'hidden') {
@@ -116,6 +118,7 @@ export default class ObjectControl extends React.Component {
116118
isFieldDuplicate={isFieldDuplicate}
117119
isFieldHidden={isFieldHidden}
118120
locale={locale}
121+
isParentListCollapsed={collapsed}
119122
/>
120123
);
121124
}

0 commit comments

Comments
 (0)