Skip to content

Commit 754bfcb

Browse files
committed
fix: FourRangeControl markmode and initial value
1 parent 6a26a97 commit 754bfcb

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/block-components/helpers/size/edit.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ const Spacing = props => {
193193
visualGuide={ paddingVisualGuide }
194194
placeholder={ props.paddingPlaceholder }
195195
marks={ presetMarks }
196+
hasCSSVariableValue={ true }
196197
/>
197198

198199
{ props.enableMargin &&
@@ -211,6 +212,7 @@ const Spacing = props => {
211212
} }
212213
visualGuide={ marginVisualGuide }
213214
marks={ presetMarks }
215+
hasCSSVariableValue={ true }
214216
/>
215217
}
216218
</>

src/components/advanced-range-control/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ AdvancedRangeControl.defaultProps = {
267267

268268
marks: undefined, // [{ value: '14px', name: 'S' }, { value: '16px', name: 'M' }]
269269
allowCustom: true,
270-
hasCSSVariableValue: false, // If the attribute can have CSS variable value (string attribute\)
270+
hasCSSVariableValue: false, // If the attribute can have CSS variable value (string attribute)
271271
isCustomPreset: false,
272272
}
273273

src/components/four-range-control/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ const FourRangeControl = memo( props => {
206206
}
207207
if ( props.marks && value ) {
208208
// Check if the current value exsits in the marks
209-
isMarkValue.first = isMarkValue.first && props.marks.some( mark => mark.value === firstValue + unit )
210-
isMarkValue.top = isMarkValue.top && props.marks.some( mark => mark.value === value.top + unit )
211-
isMarkValue.right = isMarkValue.right && props.marks.some( mark => mark.value === value.right + unit )
212-
isMarkValue.bottom = isMarkValue.bottom && props.marks.some( mark => mark.value === value.bottom + unit )
213-
isMarkValue.left = isMarkValue.left && props.marks.some( mark => mark.value === value.left + unit )
209+
const marksUnit = ( props.hasCSSVariableValue ? '' : unit )
210+
isMarkValue.first = isMarkValue.first && props.marks.some( mark => mark.value === firstValue + marksUnit )
211+
isMarkValue.top = isMarkValue.top && props.marks.some( mark => mark.value === value.top + marksUnit )
212+
isMarkValue.right = isMarkValue.right && props.marks.some( mark => mark.value === value.right + marksUnit )
213+
isMarkValue.bottom = isMarkValue.bottom && props.marks.some( mark => mark.value === value.bottom + marksUnit )
214+
isMarkValue.left = isMarkValue.left && props.marks.some( mark => mark.value === value.left + marksUnit )
214215
}
215216
const [ isFourMarkMode, setIsFourMarkMode ] = useState( isMarkValue )
216217

@@ -288,18 +289,18 @@ const FourRangeControl = memo( props => {
288289
newProps.sliderMax = props.marks.length - 1
289290
newProps.step = 1
290291

291-
// Show the marks and labels
292+
// Show the marks and names
292293
newProps.marks = props.marks.reduce( ( acc, mark, index ) => {
293294
return [
294295
{
295296
value: index,
296-
label: undefined,
297+
name: undefined,
297298
},
298299
...acc,
299300
]
300301
}, [] )
301302
newProps.renderTooltipContent = value => {
302-
return props.marks[ value ]?.label || ''
303+
return props.marks[ value ]?.name || ''
303304
}
304305

305306
// Other necessary props for steps.
@@ -321,7 +322,7 @@ const FourRangeControl = memo( props => {
321322
if ( props.marks && isMarkMode ) {
322323
rangeValue = props.marks.findIndex( mark => {
323324
const [ _value, _unit ] = extractNumberAndUnit( mark.value )
324-
return _value === value
325+
return _value === initialValue
325326
} )
326327
rangeOnChange = value => {
327328
if ( value === '' ) {
@@ -804,6 +805,7 @@ FourRangeControl.defaultProps = {
804805

805806
marks: undefined,
806807
allowCustom: true,
808+
hasCSSVariableValue: false,
807809
}
808810

809811
export default memo( FourRangeControl )

0 commit comments

Comments
 (0)