Skip to content

Commit

Permalink
fix: 修复样式中单位回显问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Sep 1, 2024
1 parent 7f11c9f commit be51911
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/editor/src/components/StyleConfig/InputPx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const InputPx = ({ value, onChange, ...props }: any) => {
const [unit, setUnit] = useState<string>('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]);

// 输入框改变
Expand All @@ -28,13 +32,12 @@ const InputPx = ({ value, onChange, ...props }: any) => {
};

const selectAfter = (
<Select defaultValue="px" onChange={handleSelect} size="small">
<Select defaultValue="px" value={unit} onChange={handleSelect} size="small">
<Option value="px">px</Option>
<Option value="%">%</Option>
<Option value="vw">vw</Option>
<Option value="vh">vh</Option>
<Option value="em">em</Option>
<Option value="rem">rem</Option>
</Select>
);

Expand Down

0 comments on commit be51911

Please sign in to comment.