Skip to content

Commit 0abe4d0

Browse files
authoredMay 30, 2024··
fix: x, y, z not accepting relative units (#195)
* fix: `x`, `y`, `z` not accepting relative units * chore: fix lint errors * refactor: use `getValueAsType` function * test: add relative unit test
1 parent 049e8a0 commit 0abe4d0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎src/reactiveTransform.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export function reactiveTransform(props: TransformProperties = {}, enableHardwar
3434
// Use translate3d by default has a better GPU optimization
3535
// And corrects scaling discrete behaviors
3636
if (enableHardwareAcceleration && (newVal.x || newVal.y || newVal.z)) {
37-
const str = [newVal.x || 0, newVal.y || 0, newVal.z || 0].map(px.transform as any).join(',')
37+
const str = [newVal.x || 0, newVal.y || 0, newVal.z || 0]
38+
.map(val => getValueAsType(val, px))
39+
.join(',')
3840

3941
result += `translate3d(${str}) `
4042

‎src/utils/style.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const valueTypes: ValueTypeMap = {
113113
export const getValueType = (key: string) => valueTypes[key]
114114

115115
/**
116-
* Transform the value using its value type, or return the value.
116+
* Transform the value using its value type if value is a `number`, otherwise return the value.
117117
*
118118
* @param value
119119
* @param type

‎tests/reactiveTransform.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ describe('reactiveTransform', () => {
5151

5252
expect(transform.value).toBe('rotateX(90deg) translateZ(0px)')
5353
})
54+
55+
it('accepts relative units when hardware acceleration is enabled', () => {
56+
const { transform } = reactiveTransform(
57+
{
58+
y: '100%',
59+
},
60+
true,
61+
)
62+
63+
expect(transform.value).toBe('translate3d(0px,100%,0px)')
64+
})
5465
})

0 commit comments

Comments
 (0)
Please sign in to comment.