Skip to content

Commit 795225b

Browse files
committed
fix (units): prevent attrNameTemplate from being re-applied.
1 parent 86a5243 commit 795225b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/util/styles/style-object.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,27 @@ class StyleObject {
288288
const unitAttrName = getAttributeName( `${ attrName }Unit`, device, state )
289289
const actualAttrName = getAttributeName( attrName, device, state )
290290

291-
let unit = hasUnits ? ( getAttribute( unitAttrName, device, state, true ) || hasUnits ) : ''
291+
let unit = hasUnits ? ( attributes[ unitAttrName ] || hasUnits ) : ''
292292
let value = attributes[ actualAttrName ]
293293

294-
/* Allow unspecified fontSizeUnit to be set based on the desktop/tablet
295-
* unit if value for fontSize is empty. */
296-
if ( ( value === '' || typeof value === 'undefined' ) && ( 0 === unitAttrName.indexOf( 'fontSizeUnit' ) ) ) {
294+
/**
295+
* Allow unspecified units to be set based on the larger used
296+
* unitdesktop/tablet unit if value is empty. For example in `rem`,
297+
* any mobile value that's automatically applied should also show
298+
* `rem`
299+
*/
300+
if ( value === '' && ( device === 'tablet' || device === 'mobile' ) ) {
297301
const desktopUnit = attributes[ getAttributeName( `${ attrName }Unit`, 'desktop', state ) ]
298302
const tabletUnit = attributes[ getAttributeName( `${ attrName }Unit`, 'tablet', state ) ]
299-
const tabletValue = attributes[ getAttributeName( attrName, 'tablet', state ) ]
300-
if ( device === 'mobile' ) {
301-
if ( tabletValue !== '' && typeof tabletValue !== 'undefined' ) {
303+
if ( device === 'tablet' ) {
304+
unit = desktopUnit
305+
} else if ( device === 'mobile' ) {
306+
const tabletValue = attributes[ getAttributeName( attrName, 'tablet', state ) ]
307+
if ( tabletValue !== '' ) {
302308
unit = tabletUnit
303309
} else {
304310
unit = desktopUnit
305311
}
306-
} else if ( device === 'tablet' ) {
307-
unit = desktopUnit
308312
}
309313
}
310314

0 commit comments

Comments
 (0)