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

bugfix/KAD-4101 Header Block Row Padding and Margin always set to px #681

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/blocks/header/children/row/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
"type": "string",
"default": "px"
},
"paddingType": {
"type": "string",
"default": "px"
},
"margin": {
"type": "array",
"default": ["", "", "", ""]
Expand All @@ -139,6 +143,10 @@
"type": "string",
"default": "px"
},
"marginType": {
"type": "string",
"default": "px"
},
"minHeight": {
"type": "number",
"default": null
Expand Down
40 changes: 28 additions & 12 deletions src/blocks/header/children/row/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ export function Edit(props) {
padding,
paddingTablet,
paddingMobile,
paddingUnit,
paddingType,
paddingUnit, // for backwards compatibility
margin,
marginTablet,
marginMobile,
marginUnit,
marginUnit, // for backwards compatibility
marginType,
minHeight,
minHeightTablet,
minHeightMobile,
Expand Down Expand Up @@ -131,6 +133,20 @@ export function Edit(props) {
}
}, []);

useEffect(() => {
// Ensure backward compatibility: Map old 'paddingUnit' to the new 'paddingType'
if (!attributes.paddingType && attributes.paddingUnit) {
setAttributes({ paddingType: attributes.paddingUnit });
}
}, [attributes.paddingUnit]);

useEffect(() => {
// Ensure backward compatibility: Map old 'paddingUnit' to the new 'paddingType'
if (!attributes.marginType && attributes.marginUnit) {
setAttributes({ marginType: attributes.marginUnit });
}
}, [attributes.marginUnit]);

const hasInsertedChildBlocks = useMemo(() => {
if (innerBlocks) {
return recursiveHasInsertedChildBlocks(innerBlocks);
Expand Down Expand Up @@ -476,16 +492,16 @@ export function Edit(props) {
onChangeMobile={(value) => setAttributes({ paddingMobile: value })}
min={0}
max={
paddingUnit === 'em' || paddingUnit === 'rem'
paddingType === 'em' || paddingType === 'rem'
? 25
: paddingUnit === 'px'
: paddingType === 'px'
? 400
: 100
}
step={paddingUnit === 'em' || paddingUnit === 'rem' ? 0.1 : 1}
unit={paddingUnit}
step={paddingType === 'em' || paddingType === 'rem' ? 0.1 : 1}
unit={paddingType}
units={['px', 'em', 'rem', '%']}
onUnit={(value) => setAttributes({ paddingUnit: value })}
onUnit={(value) => setAttributes({ paddingType: value })}
ghostDefault={['', 'sm', '', 'sm']}
/>
<ResponsiveMeasureRangeControl
Expand All @@ -498,16 +514,16 @@ export function Edit(props) {
onChangeMobile={(value) => setAttributes({ marginMobile: value })}
min={0}
max={
marginUnit === 'em' || marginUnit === 'rem'
marginType === 'em' || marginType === 'rem'
? 25
: marginUnit === 'px'
: marginType === 'px'
? 400
: 100
}
step={marginUnit === 'em' || marginUnit === 'rem' ? 0.1 : 1}
unit={marginUnit}
step={marginType === 'em' || marginType === 'rem' ? 0.1 : 1}
unit={marginType}
units={['px', 'em', 'rem', '%']}
onUnit={(value) => setAttributes({ marginUnit: value })}
onUnit={(value) => setAttributes({ marginType: value })}
/>
</KadencePanelBody>
<KadencePanelBody
Expand Down