0

I'm using the PrimeNG Carousel component in my Angular application. I've configured the responsiveOptions to adjust the number of visible items based on screen size. However, I've noticed that the breakpoints are based on the window's width, not the width of the carousel's container.

This becomes problematic when the carousel is nested within a container that doesn't span the full width of the window. In such cases, the responsiveness doesn't behave as expected.

I've searched through the documentation and various forums but haven't found a solution to make the carousel responsive based on its container's width.

  ngAfterViewInit(): void {
    this.resizeObserver = new ResizeObserver(() => {
      this.updateVisibleItems();
    });

    this.resizeObserver.observe(this.carousel.el.nativeElement);
  }

  private updateVisibleItems(): void {
    if (!this.items || !this.carousel) return;

    const numVisible = this.carousel.numVisible || this.numVisible;
    this.visibleItems = this.getDisplayItems(this.items, numVisible);
    this.cdr.markForCheck();
  }

Is there a way to configure PrimeNG Carousel to respond to the width of its container rather than the window? If not, are there any recommended workarounds or custom implementations to achieve this behavior?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.