@@ -113,11 +113,11 @@ const AdvancedRangeControl = props => {
113113 }
114114 const [ isMarkMode , setIsMarkMode ] = useState ( isMarkValue )
115115
116- // If this supports dynamic content, then the value should be saved as a String.
116+ // If this supports dynamic content and can have CSS variables, the value should be saved as a String.
117117 // Important, the attribute type for this option should be a string.
118118 const _onChange = value => {
119119 const onChangeFunc = typeof props . onChange === 'undefined' ? onChange : props . onChange
120- let newValue = props . isDynamic ? value . toString ( ) : value
120+ let newValue = props . isDynamic || props . hasCSSVariableValue ? value . toString ( ) : value
121121
122122 // On reset, allow overriding the value.
123123 if ( newValue === '' ) {
@@ -172,7 +172,7 @@ const AdvancedRangeControl = props => {
172172 }
173173
174174 // We need to change the way we handle the value and onChange if we're doing marks
175- let rangeValue = propsToPass . isDynamic ? parseFloat ( derivedValue ) : derivedValue
175+ let rangeValue = propsToPass . isDynamic || props . hasCSSVariableValue ? parseFloat ( derivedValue ) : derivedValue
176176 let rangeOnChange = _onChange
177177 if ( isMarkMode ) {
178178 rangeValue = props . marks . findIndex ( mark => {
@@ -190,8 +190,10 @@ const AdvancedRangeControl = props => {
190190 const newValue = _newValue
191191
192192 // Update the unit.
193- dispatch ( 'core/block-editor' ) . __unstableMarkNextChangeAsNotPersistent ( )
194- setAttributes ( { [ unitAttrName ] : unit } )
193+ if ( unit ) {
194+ dispatch ( 'core/block-editor' ) . __unstableMarkNextChangeAsNotPersistent ( )
195+ setAttributes ( { [ unitAttrName ] : unit } )
196+ }
195197
196198 _onChange ( newValue )
197199 }
@@ -250,6 +252,7 @@ AdvancedRangeControl.defaultProps = {
250252
251253 marks : undefined , // [{ value: '14px', label: 'S' }, { value: '16px', label: 'M' }]
252254 allowCustom : true ,
255+ hasCSSVariableValue : false ,
253256}
254257
255258export default memo ( AdvancedRangeControl , isEqual )
0 commit comments