Skip to content

Commit b2b1a11

Browse files
authored
fix: default slot should not be filtered out (#26)
1 parent 012d490 commit b2b1a11

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/runtime/server/utils/generateComponentIndex.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ export function generateComponentIndex(
151151
return acc
152152
}, {} as Record<string, PropDefinition>)
153153

154-
// Extract slots (excluding default)
154+
// Extract slots
155155
const slots = meta.slots
156-
.filter(slot => slot.name !== 'default')
157156
.reduce((acc, slot) => {
158157
acc[slot.name] = {
159158
title: slot.name.charAt(0).toUpperCase() + slot.name.slice(1).replace(/([A-Z])/g, ' $1'),

test/component-index.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,37 @@ describe('Component Index Generation', () => {
457457

458458
const component = result.components[0]
459459
expect(component.slots).toBeDefined()
460+
expect(Object.keys(component.slots)).toHaveLength(2)
460461
expect(component.slots['column-one']).toBeDefined()
461462
expect(component.slots['column-one'].title).toBeDefined()
462463
expect(component.slots['column-two']).toBeDefined()
464+
expect(component.slots.default).toBeUndefined()
465+
})
466+
467+
it('extracts default slot from component', async () => {
468+
const { generateComponentIndex } = await import('../src/runtime/server/utils/generateComponentIndex')
469+
const { resolve } = await import('node:path')
470+
471+
const mockComponents = [{
472+
pascalName: 'TestPopover',
473+
kebabName: 'test-popover',
474+
filePath: resolve(process.cwd(), 'playground/components/global/TestPopover.vue'),
475+
shortPath: 'components/global/TestPopover.vue',
476+
global: true,
477+
}]
478+
479+
const result = generateComponentIndex(
480+
mockComponents as MockComponent[],
481+
resolve(process.cwd(), 'playground/tsconfig.json'),
482+
{ category: 'Test', status: 'stable' },
483+
)
484+
485+
const component = result.components[0]
486+
expect(component.slots).toBeDefined()
487+
expect(component.slots.default).toBeDefined()
488+
expect(component.slots.default.title).toBe('Default')
489+
expect(component.slots.trigger).toBeDefined()
490+
expect(component.slots.trigger.title).toBe('Trigger')
463491
})
464492
})
465493
})

0 commit comments

Comments
 (0)