File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -396,10 +396,26 @@ function textareaInputAreaResizerFun(textareaId) {
396396 * Resizes a textarea vertically to fit its content.
397397 * @param {HTMLTextAreaElement } textarea The textarea to resize.
398398 */
399+ /**
400+ * Resizes a textarea vertically to fit its content while preserving the scroll position.
401+ * This prevents the page from scrolling when the textarea is resized.
402+ * @param {HTMLTextAreaElement } textarea The textarea to resize.
403+ */
399404function resizeVerticalTextarea ( textarea ) {
400405 if ( ! textarea ) return ;
406+
407+ // Save current scroll position
408+ const scrollPos = {
409+ top : window . pageYOffset || document . documentElement . scrollTop ,
410+ left : window . pageXOffset || document . documentElement . scrollLeft
411+ } ;
412+
413+ // Perform resize
401414 textarea . style . height = 'auto' ;
402415 textarea . style . height = `${ textarea . scrollHeight } px` ;
416+
417+ // Restore scroll position
418+ window . scrollTo ( scrollPos . left , scrollPos . top ) ;
403419}
404420
405421/**
You can’t perform that action at this time.
0 commit comments