Skip to content

Commit

Permalink
fix: revert the function to calculate if a default slot is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
iOvergaard committed Jul 11, 2024
1 parent b628ccb commit cea165e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
15 changes: 3 additions & 12 deletions packages/uui-base/lib/mixins/LabelMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,9 @@ export const LabelMixin = <T extends Constructor<LitElement>>(
private _labelSlotHasContent = false;

private labelSlotChanged(e: Event): void {
const nodes = (e.target as HTMLSlotElement).assignedNodes();

if (!nodes.length) {
this._labelSlotHasContent = false;
return;
}

// If some nodes are not TEXT_NODE, or if one of the nodes is not empty, set the slot as having content
this._labelSlotHasContent = nodes.some(
node =>
node.nodeType !== Node.TEXT_NODE || !!node.textContent?.trim().length,
);
this._labelSlotHasContent =
(e.target as HTMLSlotElement).assignedNodes({ flatten: true }).length >
0;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/uui-button/lib/uui-button.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const Template: Story = props => {
.rel=${props.rel}
look=${props.look}
color=${props.color}
label=${props.label}>
${props.slot}
</uui-button>
label=${props.label}
>${props.slot}</uui-button
>
`;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/uui-button/lib/uui-button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('UuiButton', () => {
});
it('label property is used when no default slot is provided', async () => {
const element = await fixture(
html` <uui-button label="My label"> &nbsp; </uui-button>`,
html` <uui-button label="My label"></uui-button>`,
);
expect(element.shadowRoot?.textContent).to.include('My label');
});
Expand Down
6 changes: 3 additions & 3 deletions packages/uui-toggle/lib/uui-toggle.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const AAAOverview: Story = props => html`
.labelPosition=${props.labelPosition}
?disabled=${props.disabled}
?readonly=${props.readonly}
?checked=${props.checked}>
${props.slot}
</uui-toggle>
?checked=${props.checked}
>${props.slot}</uui-toggle
>
`;
AAAOverview.storyName = 'Overview';

Expand Down

0 comments on commit cea165e

Please sign in to comment.