Skip to content

Commit c407fd1

Browse files
authored
fix(ui5-split-button): fix JS error on empty text content (#4612)
When the default slot is empty, e.g no text is provided, the this.text[0].textContent throws an error. Instead, call to this.textContent is sufficient. Fixes: #4609
1 parent 11e686f commit c407fd1

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

packages/main/src/SplitButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ class SplitButton extends UI5Element {
389389
}
390390

391391
get textButtonAccText() {
392-
return this.text[0].textContent;
392+
return this.textContent;
393393
}
394394

395395
get textButton() {

packages/main/test/pages/SplitButton.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ <h3 class="header-title">Text Direction</h3>
6666
<div class="samples-margin">
6767
<ui5-switch id="direction" text-on="RTL" text-off="LTR"></ui5-input>
6868
</div>
69+
70+
<h3>Test textContent</h3>
71+
<ui5-split-button id="emptySpBtn" design="Default"></ui5-split-button>
72+
<ui5-split-button id="defaultSpBtn" design="Default">Default</ui5-split-button>
73+
6974
</body>
7075
<script>
7176
var displayEvent = document.getElementById("displayEvent"),
@@ -84,7 +89,7 @@ <h3 class="header-title">Text Direction</h3>
8489

8590
function displayEventDetails(event) {
8691
displayEvent.value = event.type;
87-
displayElement.value = event.target.text[0].textContent;
92+
displayElement.value = event.target.textContent;
8893
setTimeout(function() {
8994
displayEvent.value = "";
9095
displayElement.value = "";

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ describe("Split Button general interaction", () => {
1313
assert.strictEqual(await arrowButton.getAttribute("design"), design, "Arrow button have proper design");
1414
});
1515

16+
it("tests textContent on 'click'", async () => {
17+
await browser.url(`http://localhost:${PORT}/test-resources/pages/SplitButton.html`);
18+
const sbEmpty = await browser.$("#emptySpBtn");
19+
const textButton1 = await sbEmpty.shadow$(".ui5-split-text-button");
20+
const sbDefault = await browser.$("#defaultSpBtn");
21+
const textButton2 = await sbDefault.shadow$(".ui5-split-text-button");
22+
const field = await browser.$("#displayElement");
23+
24+
await textButton1.click({x: 1, y: 1});
25+
assert.strictEqual(await field.getValue(), "", "Button text is empty string");
26+
27+
await textButton2.click({x: 1, y: 1});
28+
assert.strictEqual(await field.getValue(), "Default", "Button text is 'Default'");
29+
});
30+
1631
it("tests text button 'click' event (mouse)", async () => {
1732
await browser.url(`http://localhost:${PORT}/test-resources/pages/SplitButton.html`);
1833
const sbDefault = await browser.$("#sbDefault");

0 commit comments

Comments
 (0)