Skip to content

Commit a7e0370

Browse files
committed
minimize block styles, fix onchange
1 parent c45e191 commit a7e0370

File tree

2 files changed

+125
-327
lines changed

2 files changed

+125
-327
lines changed

src/block-components/alignment/edit.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -256,42 +256,34 @@ export const Edit = memo( props => {
256256
const newAttributes = {}
257257

258258
if ( deviceType === 'Desktop' ) {
259+
// If the new desktop value is the same as the tablet value, set the tablet value to ''
260+
// since tablet value will just inherit the desktop value
261+
// otherwise, set the tablet value to the old desktop value because tablet was inheriting the old value
262+
if ( innerBlockOrientationTablet === value ) {
263+
newAttributes.innerBlockOrientationTablet = ''
264+
} else {
265+
newAttributes.innerBlockOrientationTablet = innerBlockOrientation
266+
}
259267
newAttributes.innerBlockOrientation = value
260-
} else if ( deviceType === 'Tablet' && innerBlockOrientation === value ) {
261-
newAttributes.innerBlockOrientationTablet = ''
268+
newAttributes.innerBlockJustify = ''
269+
newAttributes.innerBlockAlign = ''
262270
} else if ( deviceType === 'Tablet' ) {
263-
newAttributes.innerBlockOrientationTablet = value
264-
} else if ( deviceType === 'Mobile' && _innerBlockOrientationTablet === value ) {
265-
newAttributes.innerBlockOrientationMobile = ''
266-
} else if ( deviceType === 'Mobile' ) {
267-
newAttributes.innerBlockOrientationMobile = value
268-
}
269-
270-
if ( value === 'vertical' ) { // Vertical.
271-
if ( deviceType === 'Desktop' ) {
272-
newAttributes.innerBlockJustify = ''
273-
}
274-
275-
if ( deviceType === 'Tablet' || ( deviceType === 'Desktop' && ! innerBlockOrientationTablet ) ) {
276-
newAttributes.innerBlockJustifyTablet = ''
277-
}
278-
279-
if ( deviceType === 'Mobile' || ( deviceType === 'Desktop' && ! innerBlockOrientationTablet && ! innerBlockOrientationMobile ) || ( deviceType === 'Tablet' && ! innerBlockOrientationMobile ) ) {
280-
newAttributes.innerBlockJustifyMobile = ''
281-
}
282-
} else { // Horizontal
283-
if ( deviceType === 'Desktop' ) {
284-
newAttributes.innerBlockAlign = ''
285-
}
286-
287-
if ( deviceType === 'Tablet' || ( deviceType === 'Desktop' && ! innerBlockOrientationTablet ) ) {
288-
newAttributes.innerBlockAlignTablet = ''
271+
if ( innerBlockOrientationMobile === value ) {
272+
newAttributes.innerBlockOrientationMobile = ''
273+
} else {
274+
newAttributes.innerBlockOrientationMobile = _innerBlockOrientationTablet
289275
}
290276

291-
if ( deviceType === 'Mobile' || ( deviceType === 'Desktop' && ! innerBlockOrientationTablet && ! innerBlockOrientationMobile ) || ( deviceType === 'Tablet' && ! innerBlockOrientationMobile ) ) {
292-
newAttributes.innerBlockAlignMobile = ''
293-
}
277+
// if the new tablet value is the same as the desktop value, set the tablet value to ''
278+
newAttributes.innerBlockOrientationTablet = innerBlockOrientation === value ? '' : value
279+
newAttributes.innerBlockJustifyTablet = ''
280+
newAttributes.innerBlockAlignTablet = ''
281+
} else {
282+
newAttributes.innerBlockOrientationMobile = _innerBlockOrientationTablet === value ? '' : value
283+
newAttributes.innerBlockJustifyMobile = ''
284+
newAttributes.innerBlockAlignMobile = ''
294285
}
286+
295287
setAttributes( newAttributes )
296288
} }
297289
/>

0 commit comments

Comments
 (0)