Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Responsive values cascade wrongly with different dimensions on different breakpoints [ED-4665] #15955

Merged
merged 2 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions assets/dev/js/editor/controls/base-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,21 @@ ControlBaseDataView = ControlBaseView.extend( {
},

/**
* Get the responsive child view if exists.
* Get the responsive children views if exists.
*
* @returns {ControlBaseDataView|null}
*/
getResponsiveChildView: function() {
const child = this.model.get( 'child' );
getResponsiveChildrenViews: function() {
const children = this.model.get( 'inheritors' ),
views = [];

try {
return child && this.container.panel.getControlView( child );
for ( const child of children ) {
views.push( this.container.panel.getControlView( child ) );
}
} catch ( e ) {}

return views;
},

/**
Expand Down Expand Up @@ -254,9 +259,9 @@ ControlBaseDataView = ControlBaseView.extend( {
* to be applied only from the responsive child of this control and on.
*/
propagatePlaceholder: function() {
const child = this.getResponsiveChildView();
const children = this.getResponsiveChildrenViews();

if ( child ) {
for ( const child of children ) {
child.renderWithChildren();
}
},
Expand All @@ -267,13 +272,9 @@ ControlBaseDataView = ControlBaseView.extend( {
* children.
*/
renderWithChildren: function() {
const child = this.getResponsiveChildView();

this.render();

if ( child ) {
child.renderWithChildren();
}
this.propagatePlaceholder();
},

/**
Expand Down
25 changes: 18 additions & 7 deletions assets/dev/js/editor/editor-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,11 +1252,14 @@ export default class EditorBase extends Marionette.Application {

generateResponsiveControls( controls ) {
const { activeBreakpoints } = this.config.responsive,
devices = this.breakpoints.getActiveBreakpointsList( { largeToSmall: true } ),
newControlsStack = {};
devices = this.breakpoints.getActiveBreakpointsList( { largeToSmall: true, withDesktop: true } ),
newControlsStack = {},
secondDesktopChild = devices[ devices.indexOf( 'desktop' ) + 1 ];

// Set the desktop to be the fist device, so desktop will the the parent of all devices.
devices.unshift( 'desktop' );
devices.unshift(
devices.splice( devices.indexOf( 'desktop' ), 1 )[ 0 ]
);

jQuery.each( controls, ( controlName, controlConfig ) => {
let responsiveControlName;
Expand Down Expand Up @@ -1321,12 +1324,14 @@ export default class EditorBase extends Marionette.Application {

let direction = 'max';

controlArgs.parent = null;

if ( 'desktop' !== device ) {
direction = activeBreakpoints[ device ].direction;
}

// Set the parent to be the previous device
controlArgs.parent = responsiveControlName;
// Set the parent to be the previous device
controlArgs.parent = device === secondDesktopChild ? controlName : responsiveControlName;
}

controlArgs.responsive[ direction ] = device;

Expand Down Expand Up @@ -1364,7 +1369,13 @@ export default class EditorBase extends Marionette.Application {
responsiveControlName = 'desktop' === device ? controlName : controlName + '_' + device;

if ( controlArgs.parent ) {
newControlsStack[ controlArgs.parent ].child = responsiveControlName;
const parentControlArgs = newControlsStack[ controlArgs.parent ];

if ( ! parentControlArgs.inheritors ) {
parentControlArgs.inheritors = [];
}

parentControlArgs.inheritors.push( responsiveControlName );
}

controlArgs.name = responsiveControlName;
Expand Down
2 changes: 1 addition & 1 deletion includes/base/controls-stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ final public function add_responsive_control( $id, array $args, $options = [] )
$control_name = $id . $id_suffix;

// Set this control as child of previous iteration control.
$this->update_control( $control_args['parent'], [ 'child' => $control_name ] );
$this->update_control( $control_args['parent'], [ 'inheritors' => [ $control_name ] ] );

if ( ! empty( $options['overwrite'] ) ) {
$this->update_control( $control_name, $control_args, [
Expand Down