mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	* Improve chat widget scrolling * refactor the class names to snake-case * refactor the scrollTop calculations to a helper * Add tests for scrollTopCalculationHelper Co-authored-by: Nithin David Thomas <webofnithin@gmail.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
		
			
				
	
	
		
			19 lines
		
	
	
		
			443 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			443 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const totalMessageHeight = (total, element) => {
 | 
						|
  return total + element.scrollHeight;
 | 
						|
};
 | 
						|
 | 
						|
export const calculateScrollTop = (
 | 
						|
  conversationPanelHeight,
 | 
						|
  parentHeight,
 | 
						|
  relevantMessages
 | 
						|
) => {
 | 
						|
  // add up scrollHeight of a `relevantMessages`
 | 
						|
  let combinedMessageScrollHeight = [...relevantMessages].reduce(
 | 
						|
    totalMessageHeight,
 | 
						|
    0
 | 
						|
  );
 | 
						|
  return (
 | 
						|
    conversationPanelHeight - combinedMessageScrollHeight - parentHeight / 2
 | 
						|
  );
 | 
						|
};
 |