Skip to content

Commit

Permalink
fix(vue2-masonry-wall): add missing masonry-item keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DerYeger committed Aug 2, 2023
1 parent 15bd534 commit b389379
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/nasty-moose-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@yeger/vue2-masonry-wall-docs': patch
'@yeger/vue2-masonry-wall': patch
---

add missing masonry-item keys
4 changes: 3 additions & 1 deletion docs/vue2-masonry-wall-docs/src/app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import MasonryWall from '@yeger/vue2-masonry-wall'
import { defineComponent, ref } from 'vue'
import DemoFooter from '~/demo-footer.vue'
Expand All @@ -11,6 +12,7 @@ export default defineComponent({
DemoFooter,
DemoHeader,
DemoTools,
MasonryWall,
},
setup() {
const scrollContainer = ref(null)
Expand All @@ -20,7 +22,7 @@ export default defineComponent({
},
data() {
return {
columnWidth: [256, 128, 128, 512, 128],
columnWidth: [256, 128, 128, 512, 128] as [number, ...number[]],
gap: 16,
items: [] as number[],
rtl: false,
Expand Down
20 changes: 14 additions & 6 deletions packages/vue2-masonry-wall/src/masonry-wall.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script setup lang="ts">
import type {
Column,
KeyMapper,
NonEmptyArray,
} from '@yeger/vue-masonry-wall-core'
import type { Column, NonEmptyArray } from '@yeger/vue-masonry-wall-core'
import { useMasonryWall } from '@yeger/vue-masonry-wall-core'
import type { Ref } from 'vue'
import { nextTick, onBeforeUnmount, onMounted, ref, toRefs, watch } from 'vue'
export type KeyMapper<T> = (
item: T,
column: number,
row: number,
index: number,
) => string | number | symbol | undefined
const props = withDefaults(
defineProps<{
columnWidth?: number | NonEmptyArray<number>
Expand Down Expand Up @@ -40,6 +43,7 @@ const emit = defineEmits<{
const columns = ref<Column[]>([])
const wall = ref<HTMLDivElement>() as Ref<HTMLDivElement>
const { getColumnWidthTarget } = useMasonryWall<unknown>({
columns,
emit,
Expand Down Expand Up @@ -74,7 +78,11 @@ const { getColumnWidthTarget } = useMasonryWall<unknown>({
'min-width': 0,
}"
>
<div v-for="itemIndex in column" :key="itemIndex" class="masonry-item">
<div
v-for="(itemIndex, row) in column"
:key="keyMapper(items[itemIndex], columnIndex, row, itemIndex)"
class="masonry-item"
>
<slot :item="items[itemIndex]" :index="itemIndex">
{{ items[itemIndex] }}
</slot>
Expand Down

0 comments on commit b389379

Please sign in to comment.