Skip to content

Commit

Permalink
Merge pull request #464 from bunysae/master
Browse files Browse the repository at this point in the history
Fixes #181
  • Loading branch information
piotr-s-brainhub committed May 7, 2020
2 parents b551588 + 8abcbf4 commit 6c6d436
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 0 additions & 5 deletions docs/examples/clickToChange.md
Expand Up @@ -11,8 +11,3 @@ By default, clicking the slides does nothing. You can change that behavior with
<img src={imageThree} />
</Carousel>
```

### Apple iOS
The carousel items should not be associated with the CSS
property `justify-content: center;`. This property causes
wrong justification on iOS.
22 changes: 21 additions & 1 deletion src/components/CarouselItem.js
Expand Up @@ -17,6 +17,26 @@ class CarouselItem extends PureComponent {
isDraggingEnabled: PropTypes.bool,
};

constructor(props) {
super(props);
this.childrenRef = React.createRef();
}

/* ========== Resize, if necessary. Workaround for iOS safari ========== */
componentDidUpdate() {
this.childrenRef.current.style = null;
if (this.childrenRef.current.offsetWidth > this.props.width) {
this.childrenRef.current.style.width = `${this.props.width}px`;
}
}

getChildren() {
return React.cloneElement(
this.props.children,
{ ref: this.childrenRef },
);
}

onMouseDown = event => {
this.props.onMouseDown(event, this.props.index);
};
Expand Down Expand Up @@ -46,7 +66,7 @@ class CarouselItem extends PureComponent {
onMouseDown={this.props.isDraggingEnabled ? this.onMouseDown : null}
onTouchStart={this.props.isDraggingEnabled ? this.onTouchStart : null}
>
{this.props.children}
{this.getChildren()}
</li>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/styles/CarouselItem.scss
@@ -1,5 +1,6 @@
.BrainhubCarouselItem {
display: flex;
justify-content: center;
align-items: center;
position: relative;
&.BrainhubCarouselItem--clickable {
Expand Down

0 comments on commit 6c6d436

Please sign in to comment.