Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui5-badge): allow usage of html element in the default slot #4356

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/base/src/util/isDefaultSlotProvided.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const isDefaultSlotProvided = element => {
return Array.from(element.childNodes).filter(node => {
return node.nodeType !== Node.COMMENT_NODE
&& (node.nodeType !== Node.TEXT_NODE || node.nodeValue.trim().length !== 0);
}).length;
};

export default isDefaultSlotProvided;
3 changes: 2 additions & 1 deletion packages/main/src/Badge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import isDefaultSlotProvided from "@ui5/webcomponents-base/dist/util/isDefaultSlotProvided.js";

// Template
import BadgeTemplate from "./generated/templates/BadgeTemplate.lit.js";
Expand Down Expand Up @@ -144,7 +145,7 @@ class Badge extends UI5Element {
}

get hasText() {
return !!this.textContent.trim().length;
return isDefaultSlotProvided(this);
}

get hasIcon() {
Expand Down
6 changes: 2 additions & 4 deletions packages/main/src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isCombi,
isSafari,
} from "@ui5/webcomponents-base/dist/Device.js";
import isDefaultSlotProvided from "@ui5/webcomponents-base/dist/util/isDefaultSlotProvided.js";
import ButtonDesign from "./types/ButtonDesign.js";
import ButtonTemplate from "./generated/templates/ButtonTemplate.lit.js";
import Icon from "./Icon.js";
Expand Down Expand Up @@ -421,10 +422,7 @@ class Button extends UI5Element {
}

get isIconOnly() {
return !Array.from(this.childNodes).filter(node => {
return node.nodeType !== Node.COMMENT_NODE
&& (node.nodeType !== Node.TEXT_NODE || node.nodeValue.trim().length !== 0);
}).length;
return !isDefaultSlotProvided(this);
}

get accInfo() {
Expand Down