@@ -13,7 +13,7 @@ import {
1313 useBlockSetAttributesContext ,
1414 useDeviceType ,
1515} from '~stackable/hooks'
16- import { extractNumbersAndUnits } from '~stackable/util'
16+ import { extractNumbersAndUnits , getCSSVarName } from '~stackable/util'
1717
1818/**
1919 * External dependencies
@@ -106,13 +106,18 @@ const AdvancedRangeControl = props => {
106106
107107 // Is value at first render the same as a step value? If so, do mark mode
108108 // at the start, or show custom
109- let isMarkValue = ! ! props . marks
109+ let currentMark = null
110110 if ( props . marks && value ) {
111111 const valueToCheck = value + ( props . hasCSSVariableValue ? '' : unit )
112- // Check if the current value exsits in the marks
113- isMarkValue = isMarkValue && props . marks . some ( mark => mark . value === valueToCheck )
112+ // Check if the current value exists in the marks only by their CSS variable name
113+ // to match in case the fallback size changes.
114+ props . marks . forEach ( mark => {
115+ if ( getCSSVarName ( mark . value ) === getCSSVarName ( valueToCheck ) ) {
116+ currentMark = mark
117+ }
118+ } )
114119 }
115- const [ isMarkMode , setIsMarkMode ] = useState ( isMarkValue )
120+ const [ isMarkMode , setIsMarkMode ] = useState ( ! ! currentMark )
116121
117122 // If this supports dynamic content, the value should be saved as a String.
118123 // Similar if using marks to accomodate CSS variable
@@ -135,7 +140,10 @@ const AdvancedRangeControl = props => {
135140 onChangeFunc ( newValue )
136141 }
137142
138- const derivedValue = typeof props . value === 'undefined' ? value : props . value
143+ const derivedValue = typeof props . value === 'undefined'
144+ // Use the value from the provided marks
145+ ? currentMark ? currentMark . value : value
146+ : props . value
139147
140148 const dynamicContentProps = useDynamicContentControlProps ( {
141149 value : derivedValue ,
0 commit comments