diff --git a/packages/editor/src/components/StyleConfig/InputPx.tsx b/packages/editor/src/components/StyleConfig/InputPx.tsx index 54b9dc3..54e3d23 100644 --- a/packages/editor/src/components/StyleConfig/InputPx.tsx +++ b/packages/editor/src/components/StyleConfig/InputPx.tsx @@ -6,8 +6,12 @@ const InputPx = ({ value, onChange, ...props }: any) => { const [unit, setUnit] = useState('px'); useEffect(() => { - const num = value?.toString().replace(/(px|%|vw|vh|rem|em)/, ''); + const val = value?.toString(); + const num = val?.replace(/(px|%|vw|vh|em)/, ''); if (num) setNum(num); + const reg = new RegExp('(px|%|vw|vh|em)'); + const unit = val?.match(reg); + if (unit) setUnit(unit[0]); }, [value]); // 输入框改变 @@ -28,13 +32,12 @@ const InputPx = ({ value, onChange, ...props }: any) => { }; const selectAfter = ( - - );