MM-63965 - add scroll to advanced text editor (#30983)

* MM-63965 - add scroll to advanced text editor

* show scroll only when content wraps in more than one line

* fix unit test

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Pablo Vélez
2025-05-14 15:30:04 +02:00
коммит произвёл GitHub
родитель d80d575f6c
Коммит c4b60463ff
3 изменённых файлов: 14 добавлений и 3 удалений

Просмотреть файл

@@ -11,7 +11,7 @@ exports[`components/AutosizeTextarea should match snapshot, init 1`] = `
rows={1} rows={1}
style={ style={
Object { Object {
"overflowY": "auto", "overflowY": "hidden",
} }
} }
/> />

Просмотреть файл

@@ -2,7 +2,7 @@
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import type {ChangeEvent, FormEvent, HTMLProps} from 'react'; import type {ChangeEvent, FormEvent, HTMLProps} from 'react';
import React, {useRef, useEffect, useCallback} from 'react'; import React, {useRef, useEffect, useCallback, useState} from 'react';
import type {Intersection} from '@mattermost/types/utilities'; import type {Intersection} from '@mattermost/types/utilities';
@@ -43,6 +43,9 @@ const styles = {
borderColor: 'transparent', borderColor: 'transparent',
}, },
textArea: { textArea: {
overflowY: 'hidden' as const,
},
textAreaWithScroll: {
overflowY: 'auto' as const, overflowY: 'auto' as const,
}, },
}; };
@@ -67,6 +70,7 @@ const AutosizeTextarea = React.forwardRef<HTMLTextAreaElement, Props>(({
const height = useRef(0); const height = useRef(0);
const textarea = useRef<HTMLTextAreaElement>(); const textarea = useRef<HTMLTextAreaElement>();
const referenceRef = useRef<HTMLDivElement>(null); const referenceRef = useRef<HTMLDivElement>(null);
const [showScrollbar, setShowScrollbar] = useState(false);
const recalculateHeight = () => { const recalculateHeight = () => {
if (!referenceRef.current || !textarea.current) { if (!referenceRef.current || !textarea.current) {
@@ -84,6 +88,9 @@ const AutosizeTextarea = React.forwardRef<HTMLTextAreaElement, Props>(({
height.current = scrollHeight; height.current = scrollHeight;
// Only show scrollbar if content height exceeds 44px
setShowScrollbar(scrollHeight > 44);
onHeightChange?.(scrollHeight, parseInt(style.maxHeight || '0', 10)); onHeightChange?.(scrollHeight, parseInt(style.maxHeight || '0', 10));
} }
}; };
@@ -158,7 +165,7 @@ const AutosizeTextarea = React.forwardRef<HTMLTextAreaElement, Props>(({
onInput={onInput} onInput={onInput}
value={value} value={value}
defaultValue={defaultValue} defaultValue={defaultValue}
style={styles.textArea} style={showScrollbar ? styles.textAreaWithScroll : styles.textArea}
/> />
<div style={styles.container}> <div style={styles.container}>
<div <div

Просмотреть файл

@@ -77,6 +77,10 @@
border: none; border: none;
box-shadow: none; box-shadow: none;
&.textbox-preview-area {
overflow-y: auto;
}
&:focus { &:focus {
box-shadow: none; box-shadow: none;
} }