Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexibility of isChildSwiperSlide function validation #7829

Open
odorisioe opened this issue Dec 22, 2024 · 0 comments
Open

Flexibility of isChildSwiperSlide function validation #7829

odorisioe opened this issue Dec 22, 2024 · 0 comments

Comments

@odorisioe
Copy link

Hello, I have abstracted Swiper into a compound component called Carousel with CarouselItem but I found my CarouselItem component doesn't work correctly due to the logic in the isChildSwiperSlide function:

function isChildSwiperSlide(child) {
  return child.type && child.type.displayName && child.type.displayName.includes('SwiperSlide');
}

In the example below, SwiperSlide works, but CarouselItem is ignored because the displayName does not match.

<Carousel {...args}>
  <SwiperSlide>Slide 1</SwiperSlide>
  <SwiperSlide>Slide 2</SwiperSlide>
  <SwiperSlide>Slide 3</SwiperSlide>
  <CarouselItem>Item 1</CarouselItem>
  <CarouselItem>Item 2</CarouselItem>
  <CarouselItem>Item 3</CarouselItem>
</Carousel>

Current Solution: An obvious way to deal with this would be to set CarouselItem.displayName = "CarouselItem_SwiperSlide" to make it compatible with the validation by including 'SwiperSlide'. However, this approach might break in the future with updates.

Discussion: I would like to check if there are any plans or current alternatives to make the isChildSwiperSlide function more flexible. Perhaps allow a custom validation function passed as an argument to the root component, or a custom property to check?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant