Skip to content

Commit c7a6af5

Browse files
committed
fix: min-width
1 parent 77f5605 commit c7a6af5

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

packages/components/select-input/useSingle.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,14 @@ export default function useSingle(props: SelectInputProps) {
9494
}, [props.label, classPrefix]);
9595

9696
useEffect(() => {
97-
if (showCustomElement && customElementRef.current) {
98-
const { width } = customElementRef.current.getBoundingClientRect();
99-
setCustomElementWidth(width);
100-
}
97+
if (!showCustomElement || !customElementRef.current) return;
98+
const el = customElementRef.current;
99+
// 测量真实内容宽度时,临时强制 nowrap,避免被父级 absolute 容器(受 suffixSpace 影响)压缩换行导致测量值偏小
100+
const prevWhiteSpace = el.style.whiteSpace;
101+
el.style.whiteSpace = 'nowrap';
102+
const { width } = el.getBoundingClientRect();
103+
el.style.whiteSpace = prevWhiteSpace;
104+
setCustomElementWidth((prev) => (Math.abs(prev - width) < 0.5 ? prev : width));
101105
}, [showCustomElement, singleValueDisplay]);
102106

103107
useEffect(() => {
@@ -126,7 +130,7 @@ export default function useSingle(props: SelectInputProps) {
126130
const inputRect = inputEl.getBoundingClientRect();
127131
// wrapper 右内边距 + suffix 区域 + suffixIcon 区域
128132
const space = Math.max(wrapperRect.right - inputRect.right, 0);
129-
setSuffixSpace(space);
133+
setSuffixSpace((prev) => (Math.abs(prev - space) < 0.5 ? prev : space));
130134
};
131135

132136
measure();

0 commit comments

Comments
 (0)