Skip to content

Commit

Permalink
fix(ui5-split-button): fix JS error on empty text content (#4612)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ilhan007 authored Jan 24, 2022
1 parent 11e686f commit c407fd1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/SplitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class SplitButton extends UI5Element {
}

get textButtonAccText() {
return this.text[0].textContent;
return this.textContent;
}

get textButton() {
Expand Down
7 changes: 6 additions & 1 deletion packages/main/test/pages/SplitButton.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ <h3 class="header-title">Text Direction</h3>
<div class="samples-margin">
<ui5-switch id="direction" text-on="RTL" text-off="LTR"></ui5-input>
</div>

<h3>Test textContent</h3>
<ui5-split-button id="emptySpBtn" design="Default"></ui5-split-button>
<ui5-split-button id="defaultSpBtn" design="Default">Default</ui5-split-button>

</body>
<script>
var displayEvent = document.getElementById("displayEvent"),
Expand All @@ -84,7 +89,7 @@ <h3 class="header-title">Text Direction</h3>

function displayEventDetails(event) {
displayEvent.value = event.type;
displayElement.value = event.target.text[0].textContent;
displayElement.value = event.target.textContent;
setTimeout(function() {
displayEvent.value = "";
displayElement.value = "";
Expand Down
15 changes: 15 additions & 0 deletions packages/main/test/specs/SplitButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ describe("Split Button general interaction", () => {
assert.strictEqual(await arrowButton.getAttribute("design"), design, "Arrow button have proper design");
});

it("tests textContent on 'click'", async () => {
await browser.url(`http://localhost:${PORT}/test-resources/pages/SplitButton.html`);
const sbEmpty = await browser.$("#emptySpBtn");
const textButton1 = await sbEmpty.shadow$(".ui5-split-text-button");
const sbDefault = await browser.$("#defaultSpBtn");
const textButton2 = await sbDefault.shadow$(".ui5-split-text-button");
const field = await browser.$("#displayElement");

await textButton1.click({x: 1, y: 1});
assert.strictEqual(await field.getValue(), "", "Button text is empty string");

await textButton2.click({x: 1, y: 1});
assert.strictEqual(await field.getValue(), "Default", "Button text is 'Default'");
});

it("tests text button 'click' event (mouse)", async () => {
await browser.url(`http://localhost:${PORT}/test-resources/pages/SplitButton.html`);
const sbDefault = await browser.$("#sbDefault");
Expand Down

0 comments on commit c407fd1

Please sign in to comment.