Skip to content

Commit d834ec6

Browse files
authored
fix(ui5-button): set icon-only attribute (#2567) (#2824)
Issue: When a ui5-button is created with blank text inside the component, for example <ui5-button icon="message-information"> </ui5-button>, the attribute "icon-only" isn't set correctly. Solution: Trim the node value when node is type of "TEXT_NODE" and check the length of the trimmed value. FIXES: #2567
1 parent 6895c16 commit d834ec6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/main/src/Button.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ class Button extends UI5Element {
379379
}
380380

381381
get isIconOnly() {
382-
return !Array.from(this.childNodes).filter(node => node.nodeType !== Node.COMMENT_NODE).length;
382+
return !Array.from(this.childNodes).filter(node => {
383+
return node.nodeType !== Node.COMMENT_NODE
384+
&& ( node.nodeType !== Node.TEXT_NODE || node.nodeValue.trim().length !== 0)
385+
}).length;
383386
}
384387

385388
get accInfo() {

packages/main/test/pages/Button.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
</head>
3030

3131
<body style="background-color: var(--sapBackgroundColor);">
32-
<ui5-button icon="home"><!----><!----></ui5-button>
32+
<ui5-button icon="home" id="icon-only-comment"><!----><!----></ui5-button>
33+
<ui5-button icon="text" id="icon-only-blank-text"> </ui5-button>
3334
<ui5-button>
3435
<ui5-avatar
3536
id="btnImage"

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ describe("Button general interaction", () => {
2626
assert.strictEqual(btnImage.isDisplayed(), true, "Btn image is rendered");
2727
});
2828

29+
it("tests button's icon only rendering", () => {
30+
const oButtonIconOnlyComment = browser.$("#icon-only-comment");
31+
const oButtonIconOnlyBlankText = browser.$("#icon-only-blank-text");
32+
33+
assert.strictEqual(oButtonIconOnlyComment.getAttribute("icon-only"), "", "Button comment has attribute icon-only");
34+
assert.strictEqual(oButtonIconOnlyBlankText.getAttribute("icon-only"), "", "Button blank text has attribute icon-only");
35+
});
36+
2937
it("tests click event", () => {
3038
const button = browser.$("#button1");
3139
const field = browser.$("#click-counter");
@@ -92,5 +100,5 @@ describe("Button general interaction", () => {
92100
button.removeAttribute("aria-expanded");
93101

94102
assert.strictEqual(innerButton.getAttribute("aria-expanded"), null, "Attribute is reflected");
95-
})
103+
});
96104
});

0 commit comments

Comments
 (0)