Skip to content

Commit 987087a

Browse files
committedJun 18, 2022
fix(search-select):修复搜索选择器 多选溢出(#853)
1 parent e8cfbc2 commit 987087a

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed
 

‎packages/react-search-select/src/index.tsx

+26-9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export default function SearchSelect(props: SearchSelectProps) {
7676
[selectedValue.length],
7777
);
7878
const divRef = useRef<HTMLDivElement>(null);
79+
const tagContentRef = useRef<HTMLDivElement>(null);
80+
const [tagClientWidth, setTagClientWidth] = React.useState(180);
7981

8082
const valueVerify = (value: ValueType | Array<ValueType> | undefined) => {
8183
return value !== undefined && value !== '';
@@ -221,6 +223,12 @@ export default function SearchSelect(props: SearchSelectProps) {
221223
}
222224
}
223225

226+
React.useEffect(() => {
227+
if (tagContentRef.current?.clientWidth) {
228+
setTagClientWidth(tagContentRef.current?.clientWidth);
229+
}
230+
}, [tagContentRef.current]);
231+
224232
return (
225233
<Dropdown
226234
className={cls}
@@ -275,6 +283,7 @@ export default function SearchSelect(props: SearchSelectProps) {
275283
.trim()}
276284
>
277285
<div
286+
ref={tagContentRef}
278287
className={[`${prefixCls}-tag-content`, disabled && `${prefixCls}-tag-content-disabled`]
279288
.filter(Boolean)
280289
.join(' ')
@@ -301,7 +310,15 @@ export default function SearchSelect(props: SearchSelectProps) {
301310
handleItemsClick(index, item);
302311
}}
303312
>
304-
{item.label}
313+
<span
314+
style={{
315+
maxWidth: tagClientWidth - 48,
316+
textOverflow: 'ellipsis',
317+
overflow: 'auto',
318+
}}
319+
>
320+
{item.label}
321+
</span>
305322
</Tag>
306323
);
307324
})}
@@ -323,14 +340,14 @@ export default function SearchSelect(props: SearchSelectProps) {
323340
placeholder={selectedValue.length ? '' : placeholder}
324341
/>
325342
</div>
326-
{!disabled && (selectIconType === 'close' || (selectIconType === 'loading' && loading)) && (
327-
<Icon
328-
className={`${prefixCls}-multiple-colse`}
329-
type={selectIconType}
330-
spin={loading && selectIconType === 'loading'}
331-
onClick={resetSelectedValue}
332-
/>
333-
)}
343+
{/* {!disabled && (selectIconType === 'close' || (selectIconType === 'loading' && loading)) && ( */}
344+
<Icon
345+
className={`${prefixCls}-multiple-colse`}
346+
type={'close'}
347+
spin={loading && selectIconType === 'loading'}
348+
onClick={resetSelectedValue}
349+
/>
350+
{/* )} */}
334351
</div>
335352
) : (
336353
<Input

‎packages/react-search-select/src/style/index.less

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// min-width: 50px;
99
height: 28px;
1010
}
11+
.w-input-small {
12+
width: 100%;
13+
}
1114

1215
.w-input-inner {
1316
&:hover {

0 commit comments

Comments
 (0)
Please sign in to comment.