Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Typography): fix Typography Ellipsis bug #3158

Merged
merged 2 commits into from
Oct 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/typography/ellipsis/Truncate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class Truncate extends React.Component<TruncateProps, TruncateSta
const lines = [];
const text = innerText(elements.text);

const textLines = text.split('\n').map((line) => line.split(' '));
const textLines = text.split('\n').map((line) => line.split(''));
let didTruncate = true;
const ellipsisWidth = this.ellipsisWidth(this.elements.ellipsis);

Expand All @@ -263,7 +263,7 @@ export default class Truncate extends React.Component<TruncateProps, TruncateSta
continue;
}

let resultLine: string | React.JSX.Element = textWords.join(' ');
let resultLine: string | React.JSX.Element = textWords.join('');
if (measureWidth(resultLine) <= targetWidth) {
if (textLines.length === 1) {
// Line is end of text and fits without truncating
Expand All @@ -278,7 +278,7 @@ export default class Truncate extends React.Component<TruncateProps, TruncateSta

if (line === numLines) {
// Binary search determining the longest possible line including truncate string
const textRest = textWords.join(' ');
const textRest = textWords.join('');

let lower = 0;
let upper = textRest.length - 1;
Expand Down Expand Up @@ -329,7 +329,7 @@ export default class Truncate extends React.Component<TruncateProps, TruncateSta
while (lower <= upper) {
const middle = Math.floor((lower + upper) / 2);

const testLine = textWords.slice(0, middle + 1).join(' ');
const testLine = textWords.slice(0, middle + 1).join('');

if (measureWidth(testLine) <= targetWidth) {
lower = middle + 1;
Expand All @@ -345,7 +345,7 @@ export default class Truncate extends React.Component<TruncateProps, TruncateSta
continue;
}

resultLine = textWords.slice(0, lower).join(' ');
resultLine = textWords.slice(0, lower).join('');

resultLine = restoreReplacedLinks(resultLine);

Expand Down
Loading