Skip to content

Commit c8977ba

Browse files
Merge branch 'feat/size-control-steps' of https://github.com/gambitph/Stackable into feat/size-control-steps
2 parents 523668a + 189a73e commit c8977ba

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ const AdvancedRangeControl = props => {
192192
let rangeOnChange = _onChange
193193
if ( isMarkMode ) {
194194
rangeValue = props.marks.findIndex( mark => {
195-
const [ _value, _unit ] = extractNumbersAndUnits( mark.value )[ 0 ]
196-
return _value === derivedValue
195+
let _unit, _value
196+
// If the derivedValue is a CSS variable, compare with mark's CSS variable.
197+
// Otherwise, the derivedValue is custom, so compare with raw size and units
198+
if ( typeof derivedValue === 'string' && derivedValue.startsWith( 'var' ) ) {
199+
[ _value, _unit ] = extractNumbersAndUnits( mark.value )[ 0 ]
200+
} else {
201+
[ _value, _unit ] = extractNumbersAndUnits( mark.size )[ 0 ]
202+
}
203+
return _value === derivedValue && ( _unit === '' || _unit === unit )
197204
} )
198205
rangeOnChange = ( value, property = 'value' ) => {
199206
if ( value === '' ) {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,15 @@ const FourRangeControl = memo( props => {
349349
let rangeOnChange = initialOnChange
350350
if ( props.marks && isMarkMode ) {
351351
rangeValue = props.marks.findIndex( mark => {
352-
const [ _value, _unit ] = extractNumbersAndUnits( mark.value )[ 0 ]
353-
return _value === initialValue
352+
let _unit, _value
353+
// If the initialValue is a CSS variable, compare with mark's CSS variable.
354+
// Otherwise, the initialValue is custom, so compare with raw size and units
355+
if ( typeof initialValue === 'string' && initialValue.startsWith( 'var' ) ) {
356+
[ _value, _unit ] = extractNumbersAndUnits( mark.value )[ 0 ]
357+
} else {
358+
[ _value, _unit ] = extractNumbersAndUnits( mark.size )[ 0 ]
359+
}
360+
return _value === initialValue && ( _unit === '' || _unit === unit )
354361
} )
355362
rangeOnChange = ( value, property = 'value' ) => {
356363
if ( value === '' ) {

0 commit comments

Comments
 (0)