fix icons rendering as null

pull/1922/head
konnorrogers 2024-03-13 14:24:19 -04:00
rodzic 2a4b3ee2e9
commit 418bd1c0d9
2 zmienionych plików z 34 dodań i 2 usunięć

Wyświetl plik

@ -144,12 +144,16 @@ export default class SlTree extends ShoelaceElement {
.forEach((status: 'expand' | 'collapse') => {
const existingIcon = item.querySelector(`[slot="${status}-icon"]`);
const expandButtonIcon = this.getExpandButtonIcon(status)
if (!expandButtonIcon) return
if (existingIcon === null) {
// No separator exists, add one
item.append(this.getExpandButtonIcon(status)!);
item.append(expandButtonIcon);
} else if (existingIcon.hasAttribute('data-default')) {
// A default separator exists, replace it
existingIcon.replaceWith(this.getExpandButtonIcon(status)!);
existingIcon.replaceWith(expandButtonIcon);
} else {
// The user provided a custom icon, leave it alone
}

Wyświetl plik

@ -752,4 +752,32 @@ describe('<sl-tree>', () => {
});
});
});
// https://github.com/shoelace-style/shoelace/issues/1916
it("Should not render 'null' if it can't find a custom icon", async () => {
const tree = await fixture<SlTree>(html`
<sl-tree>
<sl-tree-item>
Item 1
<sl-icon name="1-circle" slot="expand-icon"></sl-icon>
<sl-tree-item>
Item A
</sl-tree-item>
</sl-tree-item>
<sl-tree-item>
Item 2
<sl-tree-item>Item A</sl-tree-item>
<sl-tree-item>Item B</sl-tree-item>
</sl-tree-item>
<sl-tree-item>
Item 3
<sl-tree-item>Item A</sl-tree-item>
<sl-tree-item>Item B</sl-tree-item>
</sl-tree-item>
</sl-tree>
`)
expect(tree.textContent).to.not.includes("null")
})
});