File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -11,15 +11,17 @@ export default class Truncate extends Component {
1111        ] ) , 
1212        trimWhitespace : PropTypes . bool , 
1313        width : PropTypes . number , 
14-         onTruncate : PropTypes . func 
14+         onTruncate : PropTypes . func , 
15+         listenToResize : PropTypes . bool 
1516    } ; 
1617
1718    static  defaultProps  =  { 
1819        children : '' , 
1920        ellipsis : '…' , 
2021        lines : 1 , 
2122        trimWhitespace : false , 
22-         width : 0 
23+         width : 0 , 
24+         listenToResize : true 
2325    } ; 
2426
2527    state  =  { } ; 
@@ -56,7 +58,9 @@ export default class Truncate extends Component {
5658            } 
5759        } ) ; 
5860
59-         window . addEventListener ( 'resize' ,  onResize ) ; 
61+         if  ( this . props . listenToResize )  { 
62+             window . addEventListener ( 'resize' ,  onResize ) ; 
63+         } 
6064    } 
6165
6266    componentDidUpdate ( prevProps )  { 
@@ -84,7 +88,9 @@ export default class Truncate extends Component {
8488            ellipsis . parentNode . removeChild ( ellipsis ) ; 
8589        } 
8690
87-         window . removeEventListener ( 'resize' ,  onResize ) ; 
91+         if  ( this . props . listenToResize )  { 
92+             window . removeEventListener ( 'resize' ,  onResize ) ; 
93+         } 
8894
8995        window . cancelAnimationFrame ( timeout ) ; 
9096    } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments