Skip to content

Commit

Permalink
fix: 🐛 修正自动宽度下获取宽度精度的问题 (#4754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cat1007 authored Nov 19, 2024
1 parent f664d88 commit 7b21f94
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/input/useInputWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export default function useInputWidth(

const updateInputWidth = () => {
if (!inputPreRef.value || !inputRef.value) return;
// 使用 offsetWidth,会丢失精度,但是在配合 transform 的场景下,不会受到 scale 影响从而设置到错误的宽度
const width = inputPreRef.value.offsetWidth;
inputRef.value.style.width = `${width || 0}px`;
// 使用 getComputedStyle 规避 transform 带来的影响
inputRef.value.style.width = getComputedStyle(inputPreRef.value).width;
};

useResizeObserver(inputPreRef, () => {
Expand Down

0 comments on commit 7b21f94

Please sign in to comment.