Skip to content

fix(transition): Fix Splide initialization failure when type is fade and direction is LTR #1357

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/js/components/Slides/test/slide.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Splide } from '../../../core/Splide/Splide';
import { fire, init, keydown } from '../../../test';
import { format } from '../../../utils';
import { SlideComponent } from '../Slide';

import { LTR, RTL, TTB } from '../../../constants/directions';

describe( 'Slide', () => {
test( 'can assign the unique ID to the slide element.', () => {
Expand Down Expand Up @@ -382,4 +382,47 @@ describe( 'Slide', () => {
expect( Clone.isWithin( 0, 1 ) ).toBe( true );
expect( Clone.isWithin( 0, 2 ) ).toBe( true );
} );


// #1095
test( 'shows slides correctly when type is `fade` and direction is `TTB`', () => {
const splide = init( { speed: 0, perPage: 2, direction: TTB, type: 'fade', height: '100px', heightRatio: 0.3 } );
const { Slides } = splide.Components;

const Slide0 = Slides.getAt( 0 );
const Slide1 = Slides.getAt( 1 );
const Slide2 = Slides.getAt( 2 );

expect( Slide0.slide.style.transform).toBe('translateY(-0%)');
expect( Slide1.slide.style.transform).toBe('translateY(-100%)');
expect( Slide2.slide.style.transform).toBe('translateY(-200%)');
} );

// #1095
test( 'shows slides correctly when type is `fade` and direction is `RTL`', () => {
const splide = init( { speed: 0, perPage: 2, direction: RTL, type: 'fade', height: '100px', heightRatio: 0.3 } );
const { Slides } = splide.Components;

const Slide0 = Slides.getAt( 0 );
const Slide1 = Slides.getAt( 1 );
const Slide2 = Slides.getAt( 2 );

expect( Slide0.slide.style.transform).toBe('translateX(0%)');
expect( Slide1.slide.style.transform).toBe('translateX(100%)');
expect( Slide2.slide.style.transform).toBe('translateX(200%)');
} );

// #1095
test( 'shows slides correctly when type is `fade` and direction is `LTR`', () => {
const splide = init( { speed: 0, perPage: 2, direction: LTR, type: 'fade', height: '100px', heightRatio: 0.3 } );
const { Slides } = splide.Components;

const Slide0 = Slides.getAt( 0 );
const Slide1 = Slides.getAt( 1 );
const Slide2 = Slides.getAt( 2 );

expect( Slide0.slide.style.transform).toBe('translateX(-0%)');
expect( Slide1.slide.style.transform).toBe('translateX(-100%)');
expect( Slide2.slide.style.transform).toBe('translateX(-200%)');
} );
} );
14 changes: 12 additions & 2 deletions src/js/transitions/Fade/Fade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventInterface } from '../../constructors';
import { Splide } from '../../core/Splide/Splide';
import { Components, Options, TransitionComponent } from '../../types';
import { nextTick, noop } from '../../utils';

import { LTR, TTB, RTL } from '../../constants/directions';

/**
* The component for the fade transition.
Expand Down Expand Up @@ -33,7 +33,17 @@ export function Fade( Splide: Splide, Components: Components, options: Options )
*/
function init(): void {
Slides.forEach( Slide => {
Slide.style( 'transform', `translateX(-${ 100 * Slide.index }%)` );
switch (options.direction) {
case LTR:
Slide.style( 'transform', `translateX(-${ 100 * Slide.index }%)` );
break;
case RTL:
Slide.style( 'transform', `translateX(${ 100 * Slide.index }%)` );
break;
case TTB:
Slide.style( 'transform', `translateY(-${ 100 * Slide.index }%)` );
break;
}
} );
}

Expand Down