diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index ad7453dce..ce833a1a1 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -13,6 +13,7 @@ - Fix `n-upload` `multiple=false` doesn't work for drag & drop, closes [#363](https://github.com/TuSimple/naive-ui/issues/363). - Fix `n-dropdown`'s inner ``'s style. - Fix `n-menu` tooltip's inner ``'s style, closes [#338](https://github.com/TuSimple/naive-ui/issues/338). +- Fix `n-carousel` doesn't work with `v-for` children. ## 2.15.2 (2021-07-02) diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index c3f32a911..a9b033e0d 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -13,6 +13,7 @@ - 修复 `n-upload` `multiple=false` 对于拖拽不生效,关闭 [#363](https://github.com/TuSimple/naive-ui/issues/363) - 修复 `n-dropdown` 中 `` 的样式 - 修复 `n-menu` tooltip 中 `` 的样式,关闭 [#338](https://github.com/TuSimple/naive-ui/issues/338) +- 修复 `n-carousel` 无法使用 `v-for` 的子元素 ## 2.15.2 (2021-07-02) diff --git a/src/carousel/src/Carousel.tsx b/src/carousel/src/Carousel.tsx index f9879d6e3..d4c9b4877 100644 --- a/src/carousel/src/Carousel.tsx +++ b/src/carousel/src/Carousel.tsx @@ -15,7 +15,8 @@ import { indexMap } from 'seemly' import { on, off } from 'evtd' import { useConfig, useTheme } from '../../_mixins' import type { ThemeProps } from '../../_mixins' -import { ExtractPublicPropTypes } from '../../_utils' +import { flatten } from '../../_utils' +import type { ExtractPublicPropTypes } from '../../_utils' import { carouselLight } from '../styles' import type { CarouselTheme } from '../styles' import style from './styles/index.cssr' @@ -235,7 +236,8 @@ export default defineComponent({ lengthRef, $slots: { default: defaultSlot } } = this - const children = defaultSlot?.().filter((v) => v) || [] + const children = flatten(defaultSlot?.() || []) + console.log(children) const { length } = children lengthRef.value = length const leftOverflowVNode = length ? cloneVNode(children[length - 1]) : null