@@ -161,6 +161,7 @@ export function autosize(textarea: HTMLTextAreaElement, {viewportMarginBottom =
161161  function  resizeToFit ( )  { 
162162    if  ( isUserResized )  return ; 
163163    if  ( textarea . offsetWidth  <=  0  &&  textarea . offsetHeight  <=  0 )  return ; 
164+     const  previousMargin  =  textarea . style . marginBottom ; 
164165
165166    try  { 
166167      const  { top,  bottom}  =  overflowOffset ( ) ; 
@@ -176,6 +177,9 @@ export function autosize(textarea: HTMLTextAreaElement, {viewportMarginBottom =
176177      const  curHeight  =  parseFloat ( computedStyle . height ) ; 
177178      const  maxHeight  =  curHeight  +  bottom  -  adjustedViewportMarginBottom ; 
178179
180+       // In Firefox, setting auto height momentarily may cause the page to scroll up 
181+       // unexpectedly, prevent this by setting a temporary margin. 
182+       textarea . style . marginBottom  =  `${ textarea . clientHeight }  px` ; 
179183      textarea . style . height  =  'auto' ; 
180184      let  newHeight  =  textarea . scrollHeight  +  borderAddOn ; 
181185
@@ -196,6 +200,12 @@ export function autosize(textarea: HTMLTextAreaElement, {viewportMarginBottom =
196200      textarea . style . height  =  `${ newHeight }  px` ; 
197201      lastStyleHeight  =  textarea . style . height ; 
198202    }  finally  { 
203+       // restore previous margin 
204+       if  ( previousMargin )  { 
205+         textarea . style . marginBottom  =  previousMargin ; 
206+       }  else  { 
207+         textarea . style . removeProperty ( 'margin-bottom' ) ; 
208+       } 
199209      // ensure that the textarea is fully scrolled to the end, when the cursor 
200210      // is at the end during an input event 
201211      if  ( textarea . selectionStart  ===  textarea . selectionEnd  && 
0 commit comments