Skip to content

Commit

Permalink
Merge pull request #31 from vtex-apps/fix/autoplay
Browse files Browse the repository at this point in the history
Fix/autoplay
  • Loading branch information
lbebber committed Jul 8, 2019
2 parents 1d568d1 + 23148aa commit e0d5c27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Issue where the slider would flicker if autoplay delay was 0.

## [0.5.6] - 2019-07-04
### Fixed
Expand Down
22 changes: 16 additions & 6 deletions react/components/SliderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ class SliderContainerComponent extends PureComponent {
intervalRef = null

setNewInterval = () => {
const { autoplayInterval, onNextSlide } = this.props
const { autoplay, autoplayInterval, onNextSlide } = this.props

if (
!autoplay ||
typeof autoplayInterval !== 'number' ||
autoplayInterval === 0
) {
return
}

if (this.intervalRef) {
clearInterval(this.intervalRef)
Expand All @@ -18,7 +26,7 @@ class SliderContainerComponent extends PureComponent {
}

componentDidMount() {
if (this.props.autoplay) {
if (this.props.autoplay && this.props.autoplayInterval > 0) {
this.setNewInterval()
}
}
Expand Down Expand Up @@ -52,7 +60,7 @@ class SliderContainerComponent extends PureComponent {
onMouseLeave = e => {
this.eventProcedure(e, this.props.onMouseLeave, false)
}

render() {
const {
className,
Expand Down Expand Up @@ -86,7 +94,9 @@ class SliderContainerComponent extends PureComponent {
}
}

const renderForwardRef = (props, ref) => <SliderContainerComponent innerRef={ref} {...props} />
const renderForwardRef = (props, ref) => (
<SliderContainerComponent innerRef={ref} {...props} />
)
renderForwardRef.displayName = 'SliderContainer'
const SliderContainer = React.forwardRef(renderForwardRef)

Expand All @@ -104,14 +114,14 @@ SliderContainer.propsTypes = {
/** If the interval should not be executed if the mouse is on the component */
pauseOnHover: PropTypes.boolean,
/** Tag to render the component */
tag: PropTypes.string
tag: PropTypes.string,
}

SliderContainer.defaultProps = {
autoplay: false,
autoplayInterval: 5000,
pauseOnHover: true,
tag: 'div'
tag: 'div',
}

export default SliderContainer

0 comments on commit e0d5c27

Please sign in to comment.