Skip to content

Commit 52a0985

Browse files
fix(ui5-expandable-text): fix using "white-space" style in the component (#13599)
* fix(ui5-expandable-text): inherit white-space * chore: inherit white-space in the popover * chore: inherit fonts in the popover. Add tests * chore: adress code comments
1 parent 3c50320 commit 52a0985

4 files changed

Lines changed: 93 additions & 3 deletions

File tree

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,74 @@ describe("ExpandableText", () => {
223223
});
224224
});
225225

226+
describe("CSS Inheritance", () => {
227+
it("Text element inherits white-space from host", () => {
228+
const text = "This is a very long text that should be displayed";
229+
230+
cy.mount(
231+
<div style={{ whiteSpace: "pre-wrap" }}>
232+
<ExpandableText text={text} maxCharacters={9999}></ExpandableText>
233+
</div>
234+
);
235+
236+
cy.get("[ui5-expandable-text]")
237+
.shadow()
238+
.find(".ui5-exp-text-text")
239+
.should("have.css", "white-space", "pre-wrap")
240+
.and("have.css", "display", "inline");
241+
});
242+
243+
it("Text element inherits white-space 'nowrap' from host", () => {
244+
const text = "This is a very long text that should be displayed";
245+
246+
cy.mount(
247+
<div style={{ whiteSpace: "nowrap" }}>
248+
<ExpandableText text={text} maxCharacters={9999}></ExpandableText>
249+
</div>
250+
);
251+
252+
cy.get("[ui5-expandable-text]")
253+
.shadow()
254+
.find(".ui5-exp-text-text")
255+
.should("have.css", "white-space", "nowrap");
256+
});
257+
258+
it("Popover and popover text inherit white-space, font-family, and font-size from host", () => {
259+
const text = "This is a very long text that should be displayed";
260+
const maxCharacters = 5;
261+
262+
cy.mount(
263+
<div style={{ whiteSpace: "pre-line" }}>
264+
<ExpandableText text={text} maxCharacters={maxCharacters} overflowMode="Popover"></ExpandableText>
265+
</div>
266+
);
267+
268+
cy.get("[ui5-expandable-text]").shadow().as("expTextShadow");
269+
270+
cy.get("@expTextShadow")
271+
.find(".ui5-exp-text-toggle")
272+
.realClick();
273+
274+
cy.get("[ui5-expandable-text]").then($host => {
275+
const hostWhiteSpace = $host.css("white-space");
276+
const hostFontFamily = $host.css("font-family");
277+
const hostFontSize = $host.css("font-size");
278+
279+
cy.get("@expTextShadow")
280+
.find(".ui5-exp-text-popover")
281+
.should("have.css", "white-space", hostWhiteSpace)
282+
.and("have.css", "font-family", hostFontFamily)
283+
.and("have.css", "font-size", hostFontSize);
284+
285+
cy.get("@expTextShadow")
286+
.find(".ui5-exp-text-popover-text")
287+
.should("have.css", "white-space", hostWhiteSpace)
288+
.and("have.css", "font-family", hostFontFamily)
289+
.and("have.css", "font-size", hostFontSize);
290+
});
291+
});
292+
});
293+
226294
describe("Empty Indicator", () => {
227295
it("Should display empty indicator if text is empty and emptyIndicatorMode=On", () => {
228296
cy.mount(<ExpandableText text="" emptyIndicatorMode="On"></ExpandableText>);

packages/main/src/ExpandableTextTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function ExpandableTextTemplate(this: ExpandableText) {
3737
class="ui5-exp-text-popover"
3838
onClose={this._handlePopoverClose}
3939
>
40-
<Text id="popover-text">{this.text}</Text>
40+
<Text class="ui5-exp-text-popover-text" id="popover-text">{this.text}</Text>
4141
<div
4242
slot="footer"
4343
class="ui5-exp-text-footer"

packages/main/src/themes/ExpandableText.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
.ui5-exp-text-text {
1313
display: inline;
14+
white-space: inherit;
1415
}
1516

1617
.ui5-exp-text-text,
@@ -24,6 +25,13 @@
2425
color: inherit;
2526
}
2627

28+
.ui5-exp-text-popover,
29+
.ui5-exp-text-popover-text {
30+
white-space: inherit;
31+
font-family: inherit;
32+
font-size: inherit;
33+
}
34+
2735
.ui5-exp-text-popover::part(content) {
2836
padding-inline: 1rem;
2937
}

packages/main/test/pages/ExpandableText.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ <h3>max-characters=9999</h3>
2727

2828
<h3>max-characters=0</h3>
2929
<ui5-expandable-text max-characters="0" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac risus nec lorem pretium fringilla. Sed non eros nec nisl vehicula finibus. Suspendisse potenti. Quisque nec odio et est pharetra semper. Nullam nec ligula in risus laoreet pulvinar. Nullam et turpis ac eros viverra facilisis. Nullam et turpis ac eros viverra facilisis"></ui5-expandable-text>
30-
30+
3131
<h3>max-characters=-1</h3>
3232
<ui5-expandable-text max-characters="-1" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac risus nec lorem pretium fringilla. Sed non eros nec nisl vehicula finibus. Suspendisse potenti. Quisque nec odio et est pharetra semper. Nullam nec ligula in risus laoreet pulvinar. Nullam et turpis ac eros viverra facilisis. Nullam et turpis ac eros viverra facilisis"></ui5-expandable-text>
33-
33+
3434
<h3>overflowMode=Popover</h3>
3535
<ui5-expandable-text max-characters="150" overflow-mode="Popover" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac risus nec lorem pretium fringilla. Sed non eros nec nisl vehicula finibus. Suspendisse potenti. Quisque nec odio et est pharetra semper. Nullam nec ligula in risus laoreet pulvinar. Nullam et turpis ac eros viverra facilisis. Nullam et turpis ac eros viverra facilisis"></ui5-expandable-text>
3636

@@ -49,4 +49,18 @@ <h3>Off, with Text</h3>
4949

5050
<h3>RTL</h3>
5151
<ui5-expandable-text dir="rtl" text="וְאָהַבְתָּ אֵת יְיָ | אֱלֹהֶיךָ, בְּכָל-לְבָֽבְךָ, וּבְכָל-נַפְשְׁךָ, וּבְכָל-מְאֹדֶֽךָ. וְהָיוּ הַדְּבָרִים הָאֵלֶּה, אֲשֶׁר | אָֽנֹכִי מְצַוְּךָ" max-characters="50"></ui5-expandable-text>
52+
53+
<h2>Whitespaces</h2>
54+
<h3>overflowMode=Inline</h3>
55+
<ui5-expandable-text style="white-space: break-spaces" text="Simple
56+
57+
text"></ui5-expandable-text>
58+
59+
<h3>overflowMode=Popover</h3>
60+
<ui5-expandable-text style="white-space: break-spaces; font-size: 20px" overflow-mode="Popover" text="Lorem ipsum dolor sit
61+
62+
amet, consectetur adipiscing elit.
63+
64+
Donec ac risus nec lorem pretium fringilla. Sed non eros nec nisl vehicula finibus. Suspendisse potenti. Quisque nec odio et est pharetra semper. Nullam nec ligula in risus laoreet pulvinar. Nullam et turpis ac eros viverra facilisis. Nullam et turpis ac eros viverra facilisis"></ui5-expandable-text>
65+
</body>
5266
</html>

0 commit comments

Comments
 (0)