Skip to content

Commit b296bb8

Browse files
author
Itzhak Avraham
authored
Fix: Inner Section can’t be dragged into a column [ED-5910] (elementor#17258)
1 parent 3d1a5b5 commit b296bb8

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

assets/dev/js/editor/views/base-container.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ module.exports = Marionette.CompositeView.extend( {
108108
model = Object.assign( model, model.custom );
109109

110110
// Check whether the container cannot contain a section, in which case we should use an inner-section.
111-
if (
112-
$e.components.get( 'document/elements' ).utils.isValidChild( new ElementModel( model ), container.model ) &&
113-
'section' === model.elType
114-
) {
111+
if ( 'section' === model.elType ) {
115112
model.isInner = true;
116113
}
117114

@@ -120,7 +117,7 @@ module.exports = Marionette.CompositeView.extend( {
120117
title: elementor.helpers.getModelLabel( model ),
121118
} );
122119

123-
if ( options.shouldWrap || model.isInner ) {
120+
if ( options.shouldWrap ) {
124121
const containerExperiment = elementorCommon.config.experimentalFeatures.container;
125122

126123
container = $e.run( 'document/elements/create', {

assets/dev/js/editor/views/preview.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,10 @@ const Preview = BaseSectionsContainerView.extend( {
7171
},
7272

7373
createElementFromModel: function( model, options = {} ) {
74-
const shouldWrap = ! [ 'container', 'section' ].includes( model.elType || model?.get( 'elType' ) );
75-
76-
if ( ! shouldWrap ) {
77-
delete options.at;
78-
}
79-
8074
return BaseSectionsContainerView.prototype.createElementFromModel.call(
8175
this,
8276
model,
83-
{ ...options, shouldWrap },
77+
{ ...options, shouldWrap: 'container' !== model.elType },
8478
);
8579
},
8680

tests/qunit/tests/assets/dev/js/editor/document/elements/commands/create.spec.js

+39
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,45 @@ export const Create = () => {
298298
} );
299299
} );
300300
} );
301+
302+
QUnit.module( 'Drag and Drop', () => {
303+
// This module is about simulating the creation of elements by the dnd mechanism, which uses the `create`
304+
// command indirectly. This is done by the `createElementFromModel` method.
305+
QUnit.test( 'Widget: Inner Section into Column', ( assert ) => {
306+
const eSection = ElementsHelper.createSection( 1 ),
307+
eColumn = eSection.children[ 0 ],
308+
eInnerSection = ( () => {
309+
try {
310+
return eColumn.view.createElementFromModel( {
311+
elType: 'section',
312+
isInner: true,
313+
} );
314+
} catch ( e ) {
315+
return false;
316+
}
317+
} )();
318+
319+
const isInnerSectionCreated = !! eColumn.children.find( ( widget ) => eInnerSection.id === widget.id );
320+
321+
assert.equal( isInnerSectionCreated, true, 'inner section were created.' );
322+
assert.equal( eInnerSection.children?.length, DEFAULT_INNER_SECTION_COLUMNS,
323+
`'${ DEFAULT_INNER_SECTION_COLUMNS }' columns were created in the inner section.` );
324+
} );
325+
326+
QUnit.test( 'Widget: Inner Section into Preview', ( assert ) => {
327+
const eInnerSection = elementor.getPreviewContainer().view.createElementFromModel( {
328+
elType: 'section',
329+
isInner: true,
330+
} ),
331+
ePreviewChildren = elementor.getPreviewContainer().children,
332+
isInnerSectionCreated = !! ePreviewChildren[ ePreviewChildren.length - 1 ].children[ 0 ].children
333+
.find( ( widget ) => eInnerSection.id === widget.id );
334+
335+
assert.equal( isInnerSectionCreated, true, 'inner section were created.' );
336+
assert.equal( eInnerSection.children.length, DEFAULT_INNER_SECTION_COLUMNS,
337+
`'${ DEFAULT_INNER_SECTION_COLUMNS }' columns were created in the inner section.` );
338+
} );
339+
} );
301340
} );
302341
};
303342

0 commit comments

Comments
 (0)