Skip to content

Commit d834b23

Browse files
committed
pause on hover/touch
1 parent 1686c2e commit d834b23

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/controls/carousel/Carousel.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
6565
loadingComponentContainerStyles,
6666
prevButtonIconName = 'ChevronLeft',
6767
nextButtonIconName = 'ChevronRight',
68-
loadingComponent = <Spinner />
68+
loadingComponent = <Spinner />,
69+
pauseOnHover
6970
} = this.props;
7071

7172
const processing = processingState === ProcessingState.processing;
@@ -86,7 +87,12 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
8687
onClick={() => { this.onCarouselButtonClicked(false); }} />
8788
</div>
8889

89-
<div className={this.getMergedStyles(styles.contentContainer, contentContainerStyles)}>
90+
<div
91+
className={this.getMergedStyles(styles.contentContainer, contentContainerStyles)}
92+
onMouseOver={pauseOnHover ? this.pauseCycle : undefined}
93+
onTouchStart={pauseOnHover ? this.pauseCycle : undefined}
94+
onMouseLeave={pauseOnHover ? this.startCycle : undefined}
95+
onTouchEnd={pauseOnHover ? this.startCycle : undefined}>
9096
{
9197
processing &&
9298
<div className={this.getMergedStyles(styles.loadingComponent, loadingComponentContainerStyles)}>
@@ -463,4 +469,15 @@ export class Carousel extends React.Component<ICarouselProps, ICarouselState> {
463469
}
464470
}
465471
}
472+
473+
private pauseCycle = (): void => {
474+
if (this._intervalId) {
475+
if (this.props.triggerPageEvent) {
476+
clearTimeout(this._intervalId);
477+
}
478+
else {
479+
clearInterval(this._intervalId);
480+
}
481+
}
482+
}
466483
}

src/controls/carousel/ICarouselProps.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ export interface ICarouselProps {
153153
*/
154154
interval?: number | null;
155155

156+
/**
157+
* Specifies if slides cycling should pause when hovering over the content (touchStart on touch devices)
158+
*/
159+
pauseOnHover?: boolean;
160+
156161
/**
157162
* Specifies if set of slide position indicators is shown
158163
*/

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
10461046

10471047
isInfinite={true}
10481048
indicatorShape={CarouselIndicatorShape.circle}
1049+
pauseOnHover={true}
10491050

10501051
element={[
10511052
{

0 commit comments

Comments
 (0)