Skip to content

Commit 7e7b8ad

Browse files
authored
fix(ui5-text): provide more optimal truncation for single line text (#10794)
1 parent f6682b2 commit 7e7b8ad

File tree

3 files changed

+28
-47
lines changed

3 files changed

+28
-47
lines changed

packages/main/cypress/specs/Text.cy.tsx

+19-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ describe("Text", () => {
1313

1414
it("tests maxLines default behavior", () => {
1515
cy.mount(<Text >Text</Text>);
16-
cy.get("[ui5-text]").should("have.css", "-webkit-line-clamp", "none");
16+
cy.get("[ui5-text]")
17+
.should("have.css", "-webkit-box-orient", "vertical")
18+
.should("have.css", "-webkit-line-clamp", "none");
1719
});
1820

19-
it("tests maxLines", () => {
21+
it("tests maxLines = 1", () => {
2022
cy.mount(<Text maxLines={1}>Text</Text>);
21-
cy.get("[ui5-text]").should("have.css", "-webkit-line-clamp", "1");
23+
24+
cy.get("[ui5-text]")
25+
.should("have.css", "display", "inline-block")
26+
.should("have.css", "overflow", "hidden")
27+
.should("have.css", "text-overflow", "ellipsis")
28+
.should("have.css", "white-space", "nowrap");
29+
});
30+
31+
it("tests maxLines > 1", () => {
32+
cy.mount(<Text maxLines={2}>Text</Text>);
33+
34+
cy.get("[ui5-text]")
35+
.should("have.css", "overflow", "hidden")
36+
.should("have.css", "-webkit-line-clamp", "2")
37+
.should("have.css", "-webkit-box-orient", "vertical");
2238
});
2339

2440
it("tests emptyIndicatorMode", () => {

packages/main/src/themes/Text.css

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
:host {
2-
display: inline-block;
32
max-width: 100%;
43
font-size: var(--sapFontSize);
54
font-family: var(--sapFontFamily);
65
color: var(--sapTextColor);
76
line-height: normal;
8-
white-space: pre-line;
9-
word-wrap: break-word;
107
cursor: text;
8+
overflow: hidden;
9+
}
10+
11+
:host([max-lines="1"]) {
12+
display: inline-block;
13+
text-overflow: ellipsis;
14+
white-space: nowrap;
1115
}
1216

13-
:host([max-lines]) {
17+
:host(:not([max-lines="1"])) {
1418
display: -webkit-box;
1519
-webkit-line-clamp: var(--_ui5_text_max_lines);
1620
line-clamp: var(--_ui5_text_max_lines);
1721
-webkit-box-orient: vertical;
18-
overflow: hidden;
1922
white-space: normal;
23+
word-wrap: break-word;
2024
}
2125

2226
.empty-indicator-aria-label {

packages/main/test/specs/Text.spec.js

-39
This file was deleted.

0 commit comments

Comments
 (0)