Skip to content

Commit

Permalink
fix(list): list item slots wasn't passed due to slot name prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-solanki committed Feb 19, 2023
1 parent e340271 commit eec949f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
9 changes: 4 additions & 5 deletions packages/anu-vue/src/components/list/AList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ExtractPropTypes } from 'vue'
import type { ListPropItems } from './props'
import { listProps } from './props'
import type { listSlots } from './slots'
import { listItemSlot } from './slots'
import { listItemSlots } from './slots'
import { isObject } from '@/utils/helpers'
import { useGroupModel } from '@/composables'
import { AListItem } from '@/components/list-item'
Expand Down Expand Up @@ -70,12 +70,11 @@ const handleListItemClick = (item: ListPropItems[number]) => {
>
<!-- 鈩癸笍 Recursively pass down slots to child -->
<template
v-for="name in Object.keys(listItemSlot)"
#[name]="slotProps"
v-for="{ originalKey: originalSlotName, prefixedKey: updatedSlotName } in listItemSlots"
#[originalSlotName]="slotProps"
>
<!-- 鈩癸笍 v-if condition will omit passing slots. Here, we don't want to pass default slot. -->
<slot
:name="name"
:name="updatedSlotName"
:index="index"
v-bind="slotProps || {}"
/>
Expand Down
36 changes: 20 additions & 16 deletions packages/anu-vue/src/components/list/slots.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ListPropItems } from './props'
import { listItemSlots } from '@/components/list-item/slots'
import { listItemSlots as listItemComponentSlots } from '@/components/list-item/slots'
import { prefixObjectKeys } from '@/utils/helpers'

export const listOwnSlots = {
before: {},
Expand All @@ -9,22 +10,25 @@ export const listOwnSlots = {
after: {},
} as const

export const listItemSlot = {
'item-prepend': {
item: listItemSlots.prepend.item,
index: Number(),
},
'item-item': {
item: listItemSlots.item.item,
index: Number(),
},
'item-append': {
item: listItemSlots.append.item,
index: Number(),
},
} as const
// export const listItemSlots = {
// 'item-prepend': {
// item: listItemComponentSlots.prepend.item,
// index: Number(),
// },
// 'item-item': {
// item: listItemComponentSlots.item.item,
// index: Number(),
// },
// 'item-append': {
// item: listItemComponentSlots.append.item,
// index: Number(),
// },
// } as const

const { 'item-default': _, ...listItemSlots } = prefixObjectKeys(listItemComponentSlots, 'item-')
export { listItemSlots }

export const listSlots = {
...listItemSlot,
...listItemSlots,
...listOwnSlots,
} as const

0 comments on commit eec949f

Please sign in to comment.