Skip to content

Commit 6f5caac

Browse files
committed
docs(storybook): add temp fix for duplicate names
Storybook overrides properties with slots if they share a name. We fix this by adding the word 'slot' to duplicate slot names. This is a Storybook-only fix that does not change anything runtime.
1 parent 32cbedc commit 6f5caac

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

.storybook/preview.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ setCustomElements(customElements);
5252

5353
function WebComponentFormatter(customElements) {
5454
for (let tag of customElements.tags || []) {
55+
// Find all names of properties
56+
const propertyNames = (tag.properties || []).map(p => p.name);
57+
5558
for (let slot of tag.slots || []) {
5659
// Replace the name of the default slot so Storybook will show it
5760
if (typeof slot.name === 'string' && slot.name.length === 0) {
5861
slot.name = 'slot';
5962
}
6063

64+
// If the slot has the same name as a property, then add the word 'slot' to the name
65+
if (propertyNames.includes(slot.name)) {
66+
slot.name = `${slot.name} slot`;
67+
}
68+
6169
// Set type of slots
6270
if (typeof slot.type === 'undefined' || slot.type.length === 0) {
6371
slot.type = 'HTMLElement';

0 commit comments

Comments
 (0)