Skip to content

Commit f908ba3

Browse files
committed
CCM-10893 Trim trailing whitespace from truncate
1 parent 8664186 commit f908ba3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

frontend/src/__tests__/utils/truncate.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ test('returns full string if under max length', () => {
1111
test('truncates and adds ellipsis if over max length', () => {
1212
expect(truncate('This is a long string', 10)).toBe('This is a…');
1313
});
14+
15+
it('trims trailing whitespace before ellipsis', () => {
16+
expect(truncate('Hello world', 6)).toBe('Hello…');
17+
});

frontend/src/utils/truncate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const truncate = (text: string, maxLength = 50): string => {
2-
return text.length > maxLength ? text.slice(0, maxLength - 1) + '…' : text;
2+
return text.length > maxLength
3+
? text.slice(0, maxLength - 1).trimEnd() + '…'
4+
: text;
35
};

0 commit comments

Comments
 (0)