Fix the last line of editor is not visible (#19023)
Co-authored-by: Lawrence <lawrence@forem.com>
This commit is contained in:
parent
93f73636c7
commit
151a118f57
2 changed files with 18 additions and 2 deletions
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue