Skip to content

Commit f5788b8

Browse files
committed
Added maxWidth to prevent jump when rotating texts of different width
1 parent 81b7847 commit f5788b8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

components/text-rotater/text-rotater-style.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@
3838
.text-rotater__wrap {
3939
display: inline-flex;
4040
flex-direction: column;
41-
}
41+
text-align: left;
42+
}

components/text-rotater/text-rotater.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class TextRotater extends React.PureComponent {
5151
}
5252

5353
render() {
54-
const { children } = this.props;
54+
const { children, maxWidth } = this.props;
5555
const { currentIndex, contentHeight } = this.state;
5656
const childrenCount = React.Children.count(children);
5757

@@ -65,7 +65,7 @@ export default class TextRotater extends React.PureComponent {
6565
className="text-rotater__wrap"
6666
ref={ trw => (this.textRotatorWrap = trw) }
6767
onTransitionEnd={ this.handleTransitionEnd }
68-
style={ { height: contentHeight } }
68+
style={ { height: contentHeight, width: maxWidth } }
6969
>
7070
{ currentChild }
7171
{ nextChild }
@@ -85,5 +85,8 @@ TextRotater.propTypes = {
8585
children: PropTypes.arrayOf(PropTypes.node),
8686
delay: PropTypes.number,
8787
repeatDelay: PropTypes.number,
88+
// Needed to prevent jump when
89+
// rotating between texts of different widths
90+
maxWidth: PropTypes.number,
8891
};
8992

0 commit comments

Comments
 (0)