Skip to content

Commit

Permalink
fix(select): text ellipsis error (#920)
Browse files Browse the repository at this point in the history
fix #914

Co-authored-by: shiliqian <shiliqian@growingio.com>
  • Loading branch information
berber1016 and shiliqian authored Apr 2, 2021
1 parent 3ebc2bb commit da73353
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
22 changes: 15 additions & 7 deletions src/components/select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ const templatestOptions = values.map((value, index) => ({
groupValue: 'platform',
groupLabel: '应用平台',
}));

const templatestEllipsisOptions = values.map((value, index) => ({
value,
label: labels[index].repeat(6),
groupValue: 'platform',
groupLabel: '应用平台',
}))
const Template: Story<SelectProps> = (args) => (
<div>
<Select {...args} />
<br />
<br />
<Select {...args} style={{ width: '300px' }} />
</div>
<div>
<Select {...args} options={templatestEllipsisOptions} />
<br />
<br />
<Select {...args} style={{ width: '300px' }} />
<br />
<br />
<Select {...args} options={templatestEllipsisOptions} style={{ width: '300px' }} />
</div>
);
export const Default = Template.bind({});
const DefaultArgs: SelectProps = {
Expand Down
62 changes: 36 additions & 26 deletions src/components/select/Selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Selector: React.ForwardRefRenderFunction<unknown, SelectorProps> = (props,
const isEmptyValue = useMemo(() => !isEmpty(value), [value]);
const showClose = allowClear && (isEmptyValue || input) && isHovered && !disabled;
const selectValuesWidth = selectValuesRef?.current?.getBoundingClientRect()?.width;
const isShowTooltip = (selectValuesWidth || 0) - (selectorAllRef?.current?.clientWidth || 0) <= 0;
const isShowTooltip = style?.width && (selectValuesWidth || 0) - (selectorAllRef?.current?.offsetWidth || 0) <= 0;

useImperativeHandle(ref, () => ({
clientWidth: selectorRef?.current?.clientWidth,
Expand Down Expand Up @@ -131,41 +131,51 @@ const Selector: React.ForwardRefRenderFunction<unknown, SelectorProps> = (props,
}, []);

return (searchType === 'inner' || !input) && !isNil(value) ? (
<div
className={`${prefix}-item-all`}
style={{ maxWidth: style && style.width && style?.width > 0 ? 'fill-available' : undefined }}
<ToolTip
disabled={!isShowTooltip}
title={allValueLabel?.join(',')}
placement="bottom"
getTooltipContainer={()=> selectorRef?.current?.parentElement || document.body}
>
<ToolTip
overlayStyle={{ width: selectorRef?.current?.clientWidth }}
arrowPointAtCenter
disabled={!isShowTooltip}
title={allValueLabel?.join(',')}
placement="bottom"
<div
className={`${prefix}-item-all`}
style={{ maxWidth: style && style.width && style?.width > 0 ? 'fill-available' : undefined }}
>
<span ref={selectorAllRef} className={`${prefix}-item-all-text`}>
{allValueLabel?.join(',')}
</span>
</ToolTip>
</div>
<div className={`${prefix}-item-tooltip-container`}>
<span
ref={selectorAllRef}
className={classnames(`${prefix}-item-all-text`,{
[`${prefix}-item-text-visibility`]:isShowTooltip
})}
>
{allValueLabel?.join(',')}
</span>
{ isShowTooltip && <span className={classnames(`${prefix}-item-text-ellipsis`)}>{allValueLabel?.join(',')}</span>}
</div>
</div>
</ToolTip>
) : null;

};

const renderSingleValue = () => {
const text = optionLabelRenderer(value as string | number, getOptionByValue(value as string | number));
return !input && (typeof value === 'string' || typeof value === 'number') ? (
<div className={`${prefix}-item`}>
<ToolTip
disabled={!isShowTooltip}
overlayStyle={{ width: selectorRef?.current?.clientWidth }}
arrowPointAtCenter
title={text}
placement="bottom"
>
<span ref={selectorAllRef} className={`${prefix}-item-text`}>
<ToolTip
disabled={!isShowTooltip}
title={text}
placement="bottom"
getTooltipContainer={()=>selectorRef?.current?.parentElement || document.body}
>
<div className={classnames(`${prefix}-item`)}>
<span
ref={selectorAllRef}
className={classnames(`${prefix}-item-text`)}
>
{text}
</span>
</ToolTip>
</div>
</div>
</ToolTip>
) : null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ exports[`<Select /> Single Multiple options or groupOptions renders <Select />
>
<div
className="gio-select-item"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<span
className="gio-select-item-text"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
全部
</span>
Expand Down Expand Up @@ -120,11 +120,11 @@ exports[`<Select /> Single Multiple options or groupOptions renders <Select />
>
<div
className="gio-select-item"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<span
className="gio-select-item-text"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
全部
</span>
Expand Down
5 changes: 4 additions & 1 deletion src/components/select/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@

&-item {
max-width: 100%;
overflow: hidden;
font-size: @select-input-fontSize;
transition: margin 0.2s;

Expand All @@ -115,6 +116,8 @@

&-text {
overflow: hidden;
font-size: 14px;
line-height: 22px;
white-space: nowrap;
text-overflow: ellipsis;
}
Expand Down Expand Up @@ -303,7 +306,7 @@

&-isSelected {
color: @color-background-button-primary-hover;
background-color: @palette-gray-3;
background-color: @palette-gray-1;
}
}

Expand Down

1 comment on commit da73353

@vercel
Copy link

@vercel vercel bot commented on da73353 Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.