Fix the last line of editor is not visible (#19023)

Co-authored-by: Lawrence <lawrence@forem.com>
This commit is contained in:
ktmouk 2023-02-02 21:10:24 +09:00 committed by GitHub
parent 93f73636c7
commit 151a118f57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -1,5 +1,6 @@
import { useEffect, useState } from 'preact/hooks';
import { calculateTextAreaHeight } from '@utilities/calculateTextAreaHeight';
import { debounceAction } from '@utilities/debounceAction';
/**
* A helper function to get the X/Y coordinates of the current cursor position within an element.
@ -287,7 +288,7 @@ export const useTextAreaAutoResize = () => {
const height = Math.max(...allContentHeights);
const newHeight = `${height}px`;
[textArea, ...additionalElements].forEach((element) => {
allElements.forEach((element) => {
element.style['min-height'] = newHeight;
if (constrainToContentHeight) {
// Don't allow the textarea to grow to a size larger than the content
@ -298,10 +299,19 @@ export const useTextAreaAutoResize = () => {
// Resize on first attach
resizeTextArea();
// Resize on window size changes
const resizeCallback = debounceAction(() => resizeTextArea(), 300);
const resizeObserver = new ResizeObserver(resizeCallback);
resizeObserver.observe(textArea);
// Resize on subsequent value changes
textArea.addEventListener('input', resizeTextArea);
return () => textArea.removeEventListener('input', resizeTextArea);
return () => {
resizeObserver.disconnect();
textArea.removeEventListener('input', resizeTextArea);
};
}, [textArea, additionalElements, constrainToContentHeight]);
return { setTextArea, setAdditionalElements, setConstrainToContentHeight };

View file

@ -4,6 +4,12 @@ import './app/assets/javascripts/lib/xss';
global.setImmediate = global.setTimeout;
global.ResizeObserver = class ResizeObserver {
disconnect() {}
observe() {}
unobserve() {}
};
// TODO: Remove this once https://github.com/nickcolley/jest-axe/issues/147 is fixed.
const { getComputedStyle } = window;
window.getComputedStyle = (elt) => getComputedStyle(elt);