Skip to content

Commit 9e84314

Browse files
authored
fix(ui5-label): fix truncation when show-colon is set (#1079)
Fixes: #1077 The allocated width for the ":" used to be bigger than the ":" itself causing the ui5-label always to truncate, when show-colon is set to "true".
1 parent b97dc00 commit 9e84314

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

packages/main/src/themes/Label.css

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
}
2929

3030
:host(:not([wrap])[required][show-colon]) .ui5-label-text-wrapper {
31-
max-width: calc(100%-0.725rem);
31+
max-width: calc(100% - 0.725rem);
3232
}
3333

3434
:host(:not([wrap])[required]) .ui5-label-text-wrapper {
35-
max-width: calc(100%-0.475rem);
35+
max-width: calc(100% - 0.475rem);
3636
}
3737

3838
:host(:not([wrap])[show-colon]) .ui5-label-text-wrapper {
39-
max-width: calc(100%-0.3rem);
39+
max-width: calc(100% - 0.2rem);
4040
}
4141

4242
:host([show-colon]) .ui5-label-required-colon:before {

packages/main/test/pages/Label.html

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
}
1717
</script>
1818

19+
<script>delete Document.prototype.adoptedStyleSheets;</script>
20+
1921
<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
2022
<script src="../../resources/bundle.esm.js" type="module"></script>
2123
<script nomodule src="../../resources/bundle.es5.js"></script>
@@ -37,6 +39,21 @@
3739
<section class="group">
3840
<h2>Basic labels</h2>
3941
<ui5-label id="basic-label">Basic Label</ui5-label>
42+
<ui5-label show-colon id="basic-label2">Basic Label</ui5-label>
43+
<ui5-label required id="basic-label2">Basic Label</ui5-label>
44+
<ui5-label show-colon required id="basic-label3">Basic Label</ui5-label>
45+
46+
<h2>Basic long labels</h2>
47+
<ui5-label id="basic-label4">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
48+
<ui5-label show-colon id="basic-label5">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
49+
<ui5-label required id="basic-label6">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
50+
<ui5-label show-colon required id="basic-label6">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
51+
52+
<h2>Basic long labels with predefined width</h2>
53+
<ui5-label style="width: 100px" id="basic-label7">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
54+
<ui5-label style="width: 100px" show-colon id="basic-label8">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
55+
<ui5-label style="width: 100px" required id="basic-label8">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
56+
<ui5-label style="width: 100px" show-colon required id="basic-label9">Start The quick brown fox jumps over the lazy sheep End</ui5-label>
4057
</section>
4158
<section class="group">
4259
<h2>Required labels</h2>
@@ -57,6 +74,10 @@ <h2>Wrapping label</h2>
5774

5875
</section>
5976

77+
<h2>Test show-colon not forcing truncation</h2>
78+
<ui5-label id="showColon-false">Basic Label</ui5-label>
79+
<ui5-label show-colon id="showColon-true">Basic Label</ui5-label>
80+
6081
<section class="group">
6182
<h2>label + input</h2>
6283
<div style="display: flex; align-items: center">

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

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ describe("General API", () => {
2727
assert.strictEqual(requiredLabelContent, '"*"', "after's content should be *");
2828
});
2929

30+
it("tests show-colon does not force truncation", () => {
31+
const labelWithNoColon = browser.$("#showColon-false").shadow$(".ui5-label-text-wrapper");
32+
const labelWithShowColon = browser.$("#showColon-true").shadow$(".ui5-label-text-wrapper");
33+
34+
const labelWithNoColonSize = labelWithNoColon.getSize();
35+
const labelWithShowColonSize = labelWithShowColon.getSize();
36+
37+
// Comparing ui5-label(s) "Basic Label" and "Basic Label:", but just the "Basic Label" part,
38+
// that should be equal if no trunctation and not equal if truncated.
39+
assert.strictEqual(labelWithNoColonSize.width, labelWithShowColonSize.width, "Both texts are equal in width");
40+
});
41+
3042
it("should wrap the text of the label", () => {
3143
const wrappingLabel = browser.$("#wrapping-label");
3244
const truncatingLabel = browser.$("#truncated-label");

0 commit comments

Comments
 (0)