diff --git a/src/Truncate.js b/src/Truncate.js index 943ea69b..eba8e2bd 100644 --- a/src/Truncate.js +++ b/src/Truncate.js @@ -11,7 +11,8 @@ export default class Truncate extends Component { ]), trimWhitespace: PropTypes.bool, width: PropTypes.number, - onTruncate: PropTypes.func + onTruncate: PropTypes.func, + listenToResize: PropTypes.bool }; static defaultProps = { @@ -19,7 +20,8 @@ export default class Truncate extends Component { ellipsis: '…', lines: 1, trimWhitespace: false, - width: 0 + width: 0, + listenToResize: true }; state = {}; @@ -56,7 +58,9 @@ export default class Truncate extends Component { } }); - window.addEventListener('resize', onResize); + if (this.props.listenToResize) { + window.addEventListener('resize', onResize); + } } componentDidUpdate(prevProps) { @@ -84,7 +88,9 @@ export default class Truncate extends Component { ellipsis.parentNode.removeChild(ellipsis); } - window.removeEventListener('resize', onResize); + if (this.props.listenToResize) { + window.removeEventListener('resize', onResize); + } window.cancelAnimationFrame(timeout); }