Skip to content

Commit

Permalink
fix(search-select):修复搜索选择器 多选溢出(#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunLxy committed Jun 18, 2022
1 parent e8cfbc2 commit 987087a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
35 changes: 26 additions & 9 deletions packages/react-search-select/src/index.tsx
Expand Up @@ -76,6 +76,8 @@ export default function SearchSelect(props: SearchSelectProps) {
[selectedValue.length],
);
const divRef = useRef<HTMLDivElement>(null);
const tagContentRef = useRef<HTMLDivElement>(null);
const [tagClientWidth, setTagClientWidth] = React.useState(180);

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

React.useEffect(() => {
if (tagContentRef.current?.clientWidth) {
setTagClientWidth(tagContentRef.current?.clientWidth);
}
}, [tagContentRef.current]);

return (
<Dropdown
className={cls}
Expand Down Expand Up @@ -275,6 +283,7 @@ export default function SearchSelect(props: SearchSelectProps) {
.trim()}
>
<div
ref={tagContentRef}
className={[`${prefixCls}-tag-content`, disabled && `${prefixCls}-tag-content-disabled`]
.filter(Boolean)
.join(' ')
Expand All @@ -301,7 +310,15 @@ export default function SearchSelect(props: SearchSelectProps) {
handleItemsClick(index, item);
}}
>
{item.label}
<span
style={{
maxWidth: tagClientWidth - 48,
textOverflow: 'ellipsis',
overflow: 'auto',
}}
>
{item.label}
</span>
</Tag>
);
})}
Expand All @@ -323,14 +340,14 @@ export default function SearchSelect(props: SearchSelectProps) {
placeholder={selectedValue.length ? '' : placeholder}
/>
</div>
{!disabled && (selectIconType === 'close' || (selectIconType === 'loading' && loading)) && (
<Icon
className={`${prefixCls}-multiple-colse`}
type={selectIconType}
spin={loading && selectIconType === 'loading'}
onClick={resetSelectedValue}
/>
)}
{/* {!disabled && (selectIconType === 'close' || (selectIconType === 'loading' && loading)) && ( */}
<Icon
className={`${prefixCls}-multiple-colse`}
type={'close'}
spin={loading && selectIconType === 'loading'}
onClick={resetSelectedValue}
/>
{/* )} */}
</div>
) : (
<Input
Expand Down
3 changes: 3 additions & 0 deletions packages/react-search-select/src/style/index.less
Expand Up @@ -8,6 +8,9 @@
// min-width: 50px;
height: 28px;
}
.w-input-small {
width: 100%;
}

.w-input-inner {
&:hover {
Expand Down

0 comments on commit 987087a

Please sign in to comment.