react组件中的style属性使用css变量时,值会被自动添加上"px"单位,初步排查是@tarojs/react 的setStyle逻辑有问题 #12617
Labels
bug
Something isn't working
F-react
Framework - React
good first issue
Good for newcomers
T-alipay
Target - 编译到支付宝小程序
V-3
Version - 3.x
Milestone
相关平台
支付宝小程序
小程序基础库: 最新版本
使用框架: React
复现步骤
使用@tarojs/react@3.5.6库, 任意渲染一下<div style={{ lineHeight: 3, '--item-span': 2 }}>,小程序运行时会自动变成'--item-span': 2px
期望结果
组件中的sytle属性的css变量不希望自动添加px
实际结果
组件中的sytle属性的css变量自动添加px
环境信息
补充信息
具体代码位置:
taro/packages/taro-react/src/props.ts
Line 59 in 6add4ff
代码思路:
if (key[0] === '-') {
//判断了【-】的前缀时,则自动将value转换成字符串,但下方isNumber使用的不是最新值 style[key]而是传递值value,是否考虑这里直接return回去就好了
style.setProperty(key, value.toString());
}
style[key] =
isNumber(value) && IS_NON_DIMENSIONAL.test(key) === false
? value 'px'
: value == null
? ''
: value;
The text was updated successfully, but these errors were encountered: