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

Can prev and next buttons be shown when width of the carousel with multiple Items is greater than viewport width? #154

Open
ashashree14 opened this issue Apr 4, 2019 · 3 comments

Comments

@ashashree14
Copy link

Screen Shot 2019-04-04 at 4 50 42 PM
I do not want to show the prev and next buttons like above when my carousel items are visible within viewport.
The buttons should be visible when like below.
Screen Shot 2019-04-04 at 4 54 14 PM

Do we have any support from this library?

<ngu-carousel #myCarousel class="menu-tabs" [inputs]="carouselConfig" [dataSource]="dataTabsService.tabs">
  <div *nguCarouselDef="let tab;" class="item" (click)="initializeDataTab(tab)">
    <div class="tile">
      <button *ngIf="tab.closeIcon" class="pull-right close" type="button" (click)="dataTabsService.closeTab(tab.tabId)">
        ×
      </button>
      <a class="nav-link" [class.active]="dataTabsService.currentTabId == tab.tabId" id="{{ tab.tabId }}" data-toggle="tab"
        href="#{{ tab.tabId }}Content" role="tab">{{ tab.name }}</a>
    </div>
  </div>
  <button NguCarouselPrev class='leftRs' >&lt;</button>
  <button NguCarouselNext class='rightRs' >&gt;</button>
</ngu-carousel>

and in .ts file, config is

this.carouselConfig = {
      grid: { xs: 1, sm: 3, md: 4, lg: 7, all: 0 },
      slide: 1,
      speed: 600,
      point: {
        visible: false
      }
    };
@jennywlove
Copy link

jennywlove commented Jun 5, 2020

Any updates on this? I'm running into this issue as well.

@diosney
Copy link

diosney commented Jan 8, 2024

I stumbled upon this too, but still no updates.

If you need a quick fix, you can do something like this:

 // The hardcoded breakpoints the library uses.
  sliderBreakpoints = {
    sm: 768,
    md: 992,
    lg: 1200,
    xl: 1200
  };

Since the items per breakpoint is configured initially, as:

this.carouselConfig = {
   ...
   grid: { xs: 1, sm: 1, md: 2, lg: 3, all: 0 }
};

You can do something like:

  areLessOrSameVisibleItems(): boolean {
    const width      = window.innerWidth;
    let breakpointId = 'xs';

    if (width >= this.sliderBreakpoints.lg) {
      breakpointId = 'lg';
    }
    else if (width >= this.sliderBreakpoints.md) {
      breakpointId = 'md';
    }
    else if (width >= this.sliderBreakpoints.sm) {
      breakpointId = 'sm';
    }
    else {
      breakpointId = 'sm';
    }

    return (this.items.length <= this.carouselConfig.grid[breakpointId]);
  }

and in the template:

  <button NguCarouselNext class="right" [hidden]="areLessOrSameVisibleItems()">
    <mat-icon>chevron_right</mat-icon>
  </button>

  <button NguCarouselPrev class="left" [hidden]="areLessOrSameVisibleItems()">
    <mat-icon>chevron_left</mat-icon>

you can set it as a getter too.

@sheikalthaf
Copy link
Collaborator

@ashashree14 @diosney Sorry the late response, this can be easily achieved by if condition

<button 
    *ngIf="!(myCarousel.isFirst && myCarousel.isLast)"
    NguCarouselPrev
    class="leftRs"
    [style.opacity]="myCarousel.isFirst ? 0.5 : 1">
&lt;
 </button>

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

No branches or pull requests

4 participants