Skip to content

Commit cea165e

Browse files
committed
fix: revert the function to calculate if a default slot is empty
1 parent b628ccb commit cea165e

File tree

4 files changed

+10
-19
lines changed

4 files changed

+10
-19
lines changed

packages/uui-base/lib/mixins/LabelMixin.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,9 @@ export const LabelMixin = <T extends Constructor<LitElement>>(
4848
private _labelSlotHasContent = false;
4949

5050
private labelSlotChanged(e: Event): void {
51-
const nodes = (e.target as HTMLSlotElement).assignedNodes();
52-
53-
if (!nodes.length) {
54-
this._labelSlotHasContent = false;
55-
return;
56-
}
57-
58-
// If some nodes are not TEXT_NODE, or if one of the nodes is not empty, set the slot as having content
59-
this._labelSlotHasContent = nodes.some(
60-
node =>
61-
node.nodeType !== Node.TEXT_NODE || !!node.textContent?.trim().length,
62-
);
51+
this._labelSlotHasContent =
52+
(e.target as HTMLSlotElement).assignedNodes({ flatten: true }).length >
53+
0;
6354
}
6455

6556
/**

packages/uui-button/lib/uui-button.story.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ const Template: Story = props => {
108108
.rel=${props.rel}
109109
look=${props.look}
110110
color=${props.color}
111-
label=${props.label}>
112-
${props.slot}
113-
</uui-button>
111+
label=${props.label}
112+
>${props.slot}</uui-button
113+
>
114114
`;
115115
};
116116

packages/uui-button/lib/uui-button.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('UuiButton', () => {
121121
});
122122
it('label property is used when no default slot is provided', async () => {
123123
const element = await fixture(
124-
html` <uui-button label="My label"> &nbsp; </uui-button>`,
124+
html` <uui-button label="My label"></uui-button>`,
125125
);
126126
expect(element.shadowRoot?.textContent).to.include('My label');
127127
});

packages/uui-toggle/lib/uui-toggle.story.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export const AAAOverview: Story = props => html`
4040
.labelPosition=${props.labelPosition}
4141
?disabled=${props.disabled}
4242
?readonly=${props.readonly}
43-
?checked=${props.checked}>
44-
${props.slot}
45-
</uui-toggle>
43+
?checked=${props.checked}
44+
>${props.slot}</uui-toggle
45+
>
4646
`;
4747
AAAOverview.storyName = 'Overview';
4848

0 commit comments

Comments
 (0)