@@ -25,7 +25,7 @@ import { useControlHandlers } from '../base-control2/hooks'
2525import { Tooltip } from '@wordpress/components'
2626import { __ } from '@wordpress/i18n'
2727import {
28- Fragment , useState , memo ,
28+ Fragment , useState , memo , useEffect ,
2929} from '@wordpress/element'
3030import { settings } from '@wordpress/icons'
3131import { dispatch } from '@wordpress/data'
@@ -187,36 +187,42 @@ const FourRangeControl = memo( props => {
187187 : props . enableBottom ? { desktop : _valueDesktop ?. bottom , tablet : _valueTablet ?. bottom }
188188 : { desktop : _valueDesktop ?. left , tablet : _valueTablet ?. left }
189189
190- // Is value at first render the same as a step value? If so, do mark mode
191- // at the start, or show custom
192- // If no initial value, use the given default from the settings
193- const isMarkValue = {
194- first : ! ! props . marks && isMarkModeDefault ,
195- top : ! ! props . marks && isMarkModeDefault ,
196- right : ! ! props . marks && isMarkModeDefault ,
197- bottom : ! ! props . marks && isMarkModeDefault ,
198- left : ! ! props . marks && isMarkModeDefault ,
199- }
200- if ( props . marks && firstValue ) {
201- // Check if the current value exists in the marks only by their CSS variable name
202- // to match in case the fallback size changes.
203- const firstValueCssVarName = getCSSVarName ( firstValue )
204- const firstMatchedMark = props . marks . find ( mark => getCSSVarName ( mark . value ) === firstValueCssVarName )
205- isMarkValue . first = ! ! firstMatchedMark
206- if ( firstMatchedMark ) {
207- firstValue = firstMatchedMark . value
190+ const [ isFourMarkMode , setIsFourMarkMode ] = useState ( false )
191+
192+ // Set the markMode when at first render and when device type changes
193+ useEffect ( ( ) => {
194+ // Is value at first render the same as a step value? If so, do mark mode
195+ // at the start, or show custom
196+ // If no initial value, use the given default from the settings
197+ const isMarkValue = {
198+ first : ! ! props . marks && isMarkModeDefault ,
199+ top : ! ! props . marks && isMarkModeDefault ,
200+ right : ! ! props . marks && isMarkModeDefault ,
201+ bottom : ! ! props . marks && isMarkModeDefault ,
202+ left : ! ! props . marks && isMarkModeDefault ,
208203 }
209204
210- [ 'top' , 'right' , 'bottom' , 'left' ] . forEach ( side => {
211- const sideCssVarName = getCSSVarName ( value [ side ] )
212- const matchedMark = props . marks . find ( mark => getCSSVarName ( mark . value ) === sideCssVarName )
213- isMarkValue [ side ] = ! ! matchedMark
214- if ( matchedMark ) {
215- value [ side ] = matchedMark . value
205+ if ( props . marks && firstValue ) {
206+ // Check if the current value exists in the marks only by their CSS variable name
207+ // to match in case the fallback size changes.
208+ const firstValueCssVarName = getCSSVarName ( firstValue )
209+ const firstMatchedMark = props . marks . find ( mark => getCSSVarName ( mark . value ) === firstValueCssVarName )
210+ isMarkValue . first = ! ! firstMatchedMark
211+ if ( firstMatchedMark ) {
212+ firstValue = firstMatchedMark . value
216213 }
217- } )
218- }
219- const [ isFourMarkMode , setIsFourMarkMode ] = useState ( isMarkValue )
214+
215+ [ 'top' , 'right' , 'bottom' , 'left' ] . forEach ( side => {
216+ const sideCssVarName = getCSSVarName ( value [ side ] )
217+ const matchedMark = props . marks . find ( mark => getCSSVarName ( mark . value ) === sideCssVarName )
218+ isMarkValue [ side ] = ! ! matchedMark
219+ if ( matchedMark ) {
220+ value [ side ] = matchedMark . value
221+ }
222+ } )
223+ setIsFourMarkMode ( isMarkValue )
224+ }
225+ } , [ deviceType ] )
220226
221227 const onChangeAll = _newValue => {
222228 const newValue = props . marks ? String ( _newValue ) : _newValue
0 commit comments