Skip to content

Commit 326c5b7

Browse files
committed
fix: handle line getting cut and tooltip not shown
1 parent 4bee22e commit 326c5b7

File tree

3 files changed

+70
-62
lines changed

3 files changed

+70
-62
lines changed

packages/web/src/components/search/SearchBox.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import SearchSvg from '../shared/SearchSvg';
5353
import { TagItem, TagsContainer } from '../../styles/Tags';
5454
import Container from '../../styles/Container';
5555
import Title from '../../styles/Title';
56-
import { Actions as ActionContainer, searchboxSuggestions, suggestionsContainer, TextArea } from '../../styles/Input';
56+
import { Actions as ActionContainer, searchboxSuggestions, Suggestion, SuggestionDescription, suggestionsContainer, TextArea } from '../../styles/Input';
5757
import Button from '../../styles/Button';
5858
import SuggestionItem from './addons/SuggestionItem';
5959
import {
@@ -68,7 +68,6 @@ import CancelSvg from '../shared/CancelSvg';
6868
import CustomSvg from '../shared/CustomSvg';
6969
import SuggestionWrapper from './addons/SuggestionWrapper';
7070
import AutofillSvg from '../shared/AutofillSvg';
71-
import Flex from '../../styles/Flex';
7271
import AutosuggestFooterContainer from '../../styles/AutoSuggestFooterContainer';
7372
import HOOKS from '../../utils/hooks';
7473
import { Answer, Footer, SearchBoxAISection, SourceTags } from '../../styles/SearchBoxAI';
@@ -2077,29 +2076,28 @@ const SearchBox = (props) => {
20772076
type={`${sectionItem._suggestion_type}-search-icon`}
20782077
/>
20792078
</div>
2080-
<div className="trim">
2081-
<Flex direction="column">
2082-
{sectionItem.label && (
2083-
<TextWithTooltip
2084-
title={sectionItem.label}
2085-
className="section-list-item__label"
2086-
innerHTML={
2087-
sectionItem.label
2088-
}
2089-
/>
2090-
)}
2091-
{sectionItem.description && (
2092-
<div
2093-
className="section-list-item__description"
2094-
dangerouslySetInnerHTML={{
2095-
__html: XSS(
2096-
sectionItem.description,
2097-
),
2098-
}}
2099-
/>
2100-
)}
2101-
</Flex>
2102-
</div>
2079+
<Suggestion direction="column">
2080+
{sectionItem.label && (
2081+
<TextWithTooltip
2082+
title={sectionItem.label}
2083+
className="section-list-item__label"
2084+
innerHTML={
2085+
sectionItem.label
2086+
}
2087+
/>
2088+
)}
2089+
{sectionItem.description && (
2090+
<SuggestionDescription
2091+
lines={1}
2092+
className="section-list-item__description"
2093+
dangerouslySetInnerHTML={{
2094+
__html: XSS(
2095+
sectionItem.description,
2096+
),
2097+
}}
2098+
/>
2099+
)}
2100+
</Suggestion>
21032101
{getActionIcon(
21042102
sectionItem,
21052103
)}

packages/web/src/components/search/addons/TextWithTooltip.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import { string } from 'prop-types';
22
import types from '@appbaseio/reactivecore/lib/utils/types';
33
import React, { useState, useEffect, useRef } from 'react';
44

5+
import styled from '@emotion/styled';
6+
7+
const Container = styled.div`
8+
width: 100%;
9+
overflow: hidden;
10+
white-space: nowrap;
11+
text-overflow: ellipsis;
12+
`;
13+
14+
const Content = styled.span`
15+
display: ${props => (props.isOverflowing ? 'inline' : 'block')};
16+
`;
17+
518
/**
619
* Shows tooltip when text content overflows out of the container
720
* */
@@ -15,6 +28,7 @@ const TextWithTooltip = ({
1528
useEffect(() => {
1629
const container = containerRef.current;
1730
const content = contentRef.current;
31+
1832
if (container && content) {
1933
const containerWidth = container.offsetWidth;
2034
const contentWidth = content.scrollWidth;
@@ -24,16 +38,17 @@ const TextWithTooltip = ({
2438
}, [innerHTML, title]);
2539

2640
return (
27-
<div title={isOverflowing ? title : ''} ref={containerRef} >
28-
<div
41+
<Container title={isOverflowing ? title : ''} ref={containerRef} >
42+
<Content
2943
className={className}
3044
style={style}
45+
isOverflowing={isOverflowing}
3146
ref={contentRef}
3247
dangerouslySetInnerHTML={{
3348
__html: innerHTML,
3449
}}
3550
/>
36-
</div>
51+
</Container>
3752
);
3853
};
3954

packages/web/src/styles/Input.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import styled from '@emotion/styled';
22
import { css } from '@emotion/core';
3+
import Flex from './Flex';
34

45
const alertBorder = ({ theme }) => `
56
border: 1px solid ${theme.colors.alertColor};
@@ -194,19 +195,8 @@ const suggestions = (themePreset, theme) => css`
194195
cursor: pointer;
195196
padding: 10px;
196197
user-select: none;
197-
198-
& > .trim {
199-
display: -webkit-box;
200-
display: flex;
201-
width: 100%;
202-
max-height: 2.3rem;
203-
line-height: 1.2rem;
204-
-webkit-line-clamp: 2;
205-
-webkit-box-orient: vertical;
206-
overflow: hidden;
207-
text-overflow: ellipsis;
208-
white-space: nowrap;
209-
}
198+
width: 100%;
199+
overflow: hidden;
210200
211201
&:hover,
212202
&:focus {
@@ -217,6 +207,15 @@ const suggestions = (themePreset, theme) => css`
217207
${themePreset === 'dark' && theme && dark(theme)};
218208
`;
219209

210+
const TrimmedText = styled.div`
211+
display: -webkit-box;
212+
width: 100%;
213+
-webkit-line-clamp: ${props => props.lines || 2};
214+
-webkit-box-orient: vertical;
215+
overflow: hidden;
216+
text-overflow: ellipsis;
217+
`;
218+
220219
const searchboxSuggestions = (themePreset, theme) => css`
221220
${suggestions(themePreset, theme)};
222221
@@ -278,29 +277,22 @@ const searchboxSuggestions = (themePreset, theme) => css`
278277
.section-list {
279278
padding-left: 0;
280279
}
281-
.section-list-item {
282-
&__label,
283-
&__description {
284-
overflow: hidden;
285-
text-overflow: ellipsis;
286-
white-space: nowrap;
287-
288-
* {
289-
margin: 0;
290-
padding: 0;
291-
}
292-
}
293-
294-
&__label {
295-
}
296-
&__description {
297-
margin-top: 5px;
298-
opacity: 0.7;
299-
font-size: 12px;
300-
}
301-
}
302280
}
303281
`;
282+
const Suggestion = styled(Flex)`
283+
white-space: nowrap;
284+
overflow: hidden;
285+
text-overflow: ellipsis;
286+
width: 100%;
287+
`;
288+
289+
const SuggestionDescription = styled(TrimmedText)`
290+
overflow: hidden;
291+
text-overflow: ellipsis;
292+
margin-top: 5px;
293+
opacity: 0.7;
294+
font-size: 12px;
295+
`;
304296

305297
const suggestionsContainer = css`
306298
position: relative;
@@ -346,4 +338,7 @@ export {
346338
searchboxSuggestions,
347339
TextArea,
348340
Actions,
341+
TrimmedText,
342+
Suggestion,
343+
SuggestionDescription,
349344
};

0 commit comments

Comments
 (0)