Skip to content

Commit 787a54a

Browse files
committed
fix: make fontSizes string to store CSS variables
1 parent 9c36600 commit 787a54a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/block-components/typography/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { deprecatedAddAttributes } from './deprecated'
33
const typographyAttributes = {
44
fontSize: {
55
stkResponsive: true,
6-
type: 'number',
6+
type: 'string',
77
default: '',
88
stkUnits: 'px',
99
},

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

255258
export default memo( AdvancedRangeControl, isEqual )

0 commit comments

Comments
 (0)